ethereumutil

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContractInvalidError = "contract_invalid_error"
	EthClientError       = "ethereum_client_error"
)
View Source
const (
	Retries = 5
	Timeout = 5
	Fast    = "fast"
	Fastest = "fastest"
	Average = "average"
)
View Source
const (
	DefaultGasLimit      uint64  = 300000       // Ethereum default gas limit in gas units
	DefaultGasPrice      uint64  = 160000000000 // Ethereum default gas price in wei
	DefaultGasMultiplier float64 = 1.5          // Ethereum default gas multiplier
	DefaultMaxGasPrice   uint64  = 300000000000 // Ethereum max gas price in wei
)

Variables

View Source
var DefaultGasParams = NewDefaultGasParams()

Functions

func ValidateEthereumAddress

func ValidateEthereumAddress(address string) error

Types

type Client

type Client struct {
	Client                      *ethclient.Client
	RegistrationContract        *contracts.Registration
	CoreContract                *contracts.Core
	GasLimit                    uint64
	GasPrice                    *big.Int
	GasMultiplier               float64
	MaxGasPrice                 *big.Int
	EgsAPIKey                   string
	EGSSpeed                    string
	RegistrationContractAddress ethcommon.Address
	StarkContractAddress        ethcommon.Address
}

Client to interact with ethereum blockchain

func NewEthereumClient

func NewEthereumClient(url string, params GasParams) (*Client, error)

NewEthereumClient returns a new ethereum client

func NewEthereumClientAndAttachContracts

func NewEthereumClientAndAttachContracts(
	ctx context.Context,
	cfg *config.Config,
	gasParams GasParams) (*Client, error)

NewEthereumClientAndAttachContracts is a factory method to create a new ethereum client and attaches registration and core contracts to the client.

func (*Client) BuildTransactOpts

func (e *Client) BuildTransactOpts(ctx context.Context, l1signer signers.L1Signer) (*bind.TransactOpts, error)

func (*Client) NewIERC20Contract

func (e *Client) NewIERC20Contract(ctx context.Context, address string) (*contracts.IERC20, error)

func (*Client) NewIERC721Contract

func (e *Client) NewIERC721Contract(ctx context.Context, address string) (*contracts.IERC721, error)

type EtherClient

type EtherClient interface {
	NewIERC20Contract(ctx context.Context, address string) (*contracts.IERC20, error)
	NewIERC721Contract(ctx context.Context, address string) (*contracts.IERC721, error)
}

type GasParams

type GasParams struct {
	GasLimit uint64
	GasPrice *big.Int
	// GasMultiplier is used to adjust the GasPrice returned by the method SuggestGasPrice (eth_gasPrice)
	// to control the speed of the ethereum transaction. E.g. a multiplier of 1.5 would set the gas price
	// at 1.5 times the suggested gas price and should process faster than simply using the suggested gas price.
	GasMultiplier float64
	MaxGasPrice   *big.Int
	// Eth gas station (EGS) API key https://ethgasstation.info
	EgsAPIKey string
	// Eth gas station (EGS) speed https://ethgasstation.info
	EGSSpeed string
}

GasParams are used to set the gas limit and gas price. When EgsAPIKey is provided, Client.BuildTransactOpts will attempt to set the gas price returned from eth gas station. If the api call to eth gas station fails, the gas price will be set at the (Network suggested price * GasMultiplier) unless MaxGasPrice is lower, then gas price will be set at MaxGasPrice. When EgsAPIKey is an empty string or if the api call to eth gas station fails, the gas price will be set at the (Network suggested price * GasMultiplier) unless MaxGasPrice is lower, then gas price will be set at MaxGasPrice.

func NewDefaultGasParams

func NewDefaultGasParams() GasParams

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL