ethclient

package
v0.0.0-...-2515fb6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ETH_NODE_URL_KEY = "eth-node-url"
)

Variables

View Source
var ErrEnvRPCSet = errors.New("cannot set rpc url when using env store, switch to keychain store by removing ETH_NODE_URL env var")
View Source
var ErrNotSupportedChain = fmt.Errorf("chain is not supported")

Functions

func GetPublicRPCURLs

func GetPublicRPCURLs(chainID int) ([]string, error)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client defines typed wrappers for the Ethereum RPC API.

func NewClient

func NewClient(c RPCClient) *Client

NewClient creates a client that uses the given RPC client.

func (*Client) BalanceAt

func (ec *Client) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)

BalanceAt returns the wei balance of the given account. The block number can be nil, in which case the balance is taken from the latest known block.

func (*Client) BlockNumber

func (ec *Client) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber returns the most recent block number

func (*Client) CallContract

func (ec *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.

blockNumber selects the block height at which the call runs. It can be nil, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available.

func (*Client) ChainID

func (ec *Client) ChainID(ctx context.Context) (*big.Int, error)

ChainID retrieves the current chain ID for transaction replay protection.

func (*Client) Client

func (ec *Client) Client() RPCClient

Client gets the underlying RPC client.

func (*Client) Close

func (ec *Client) Close()

Close closes the underlying RPC connection.

func (*Client) CodeAt

func (ec *Client) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)

CodeAt returns the contract code of the given account. The block number can be nil, in which case the code is taken from the latest known block.

func (*Client) EstimateGas

func (ec *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

EstimateGas tries to estimate the gas needed to execute a specific transaction based on the current pending state of the backend blockchain. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.

func (*Client) FilterLogs

func (ec *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

FilterLogs executes a filter query.

func (*Client) HeaderByNumber

func (ec *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*Client) PendingCodeAt

func (ec *Client) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

PendingCodeAt returns the contract code of the given account in the pending state.

func (*Client) PendingNonceAt

func (ec *Client) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.

func (*Client) SendTransaction

func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction injects a signed transaction into the pending pool for execution.

If the transaction was a contract creation use the TransactionReceipt method to get the contract address after the transaction has been mined.

func (*Client) SubscribeFilterLogs

func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs subscribes to the results of a streaming filter query.

func (*Client) SuggestGasPrice

func (ec *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.

func (*Client) SuggestGasTipCap

func (ec *Client) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

SuggestGasTipCap retrieves the currently suggested gas tip cap after 1559 to allow a timely execution of a transaction.

func (*Client) TransactionReceipt

func (ec *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

TransactionReceipt returns the receipt of a transaction by transaction hash. Note that the receipt is not available for pending transactions.

type JSONError

type JSONError interface {
	Error() string
	ErrorCode() int
	ErrorData() interface{}
}

type RPCClient

type RPCClient interface {
	Close()
	BatchCallContext(context.Context, []rpc.BatchElem) error
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error)
}

type RPCClientModifiable

type RPCClientModifiable interface {
	RPCClient
	GetURLs() []string
	SetURLs(urls []string) error
}

type RPCClientMultiple

type RPCClientMultiple struct {
	// contains filtered or unexported fields
}

Wrapper around multiple RPC clients, used to retry calls on multiple endpoints

func NewRPCClientMultiple

func NewRPCClientMultiple(urls []string, log lib.ILogger) (*RPCClientMultiple, error)

func (*RPCClientMultiple) BatchCallContext

func (c *RPCClientMultiple) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error

func (*RPCClientMultiple) CallContext

func (c *RPCClientMultiple) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

func (*RPCClientMultiple) Close

func (c *RPCClientMultiple) Close()

func (*RPCClientMultiple) EthSubscribe

func (c *RPCClientMultiple) EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error)

func (*RPCClientMultiple) GetURLs

func (c *RPCClientMultiple) GetURLs() []string

func (*RPCClientMultiple) SetURLs

func (c *RPCClientMultiple) SetURLs(urls []string) error

type RPCClientStoreEnv

type RPCClientStoreEnv struct {
	// contains filtered or unexported fields
}

func (*RPCClientStoreEnv) GetClient

func (p *RPCClientStoreEnv) GetClient() RPCClient

func (*RPCClientStoreEnv) GetURLs

func (p *RPCClientStoreEnv) GetURLs() []string

func (*RPCClientStoreEnv) RemoveURLs

func (p *RPCClientStoreEnv) RemoveURLs() error

func (*RPCClientStoreEnv) SetURLs

func (p *RPCClientStoreEnv) SetURLs(urls []string) error

type RPCClientStoreKeychain

type RPCClientStoreKeychain struct {
	// contains filtered or unexported fields
}

func NewRPCClientStoreKeychain

func NewRPCClientStoreKeychain(storage interfaces.KeyValueStorage, rpcClient RPCClientModifiable, log lib.ILogger) *RPCClientStoreKeychain

func (*RPCClientStoreKeychain) GetClient

func (p *RPCClientStoreKeychain) GetClient() RPCClient

func (*RPCClientStoreKeychain) GetURLs

func (p *RPCClientStoreKeychain) GetURLs() []string

func (*RPCClientStoreKeychain) RemoveURLs

func (p *RPCClientStoreKeychain) RemoveURLs() error

func (*RPCClientStoreKeychain) SetURLs

func (p *RPCClientStoreKeychain) SetURLs(urls []string) error

type RPCEndpointsPersister

type RPCEndpointsPersister interface {
	GetURLs() []string
	SetURLs(urls []string) error
	RemoveURLs() error
	GetClient() RPCClient
}

func ConfigureRPCClientStore

func ConfigureRPCClientStore(storage interfaces.KeyValueStorage, envURLs []string, chainID int, log lib.ILogger) (RPCEndpointsPersister, error)

Jump to

Keyboard shortcuts

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