Documentation ¶
Index ¶
- type Client
- func (c *Client) Accounts(ctx context.Context) ([]types.Address, error)
- func (c *Client) BlockByHash(ctx context.Context, hash types.Hash, full bool) (*types.Block, error)
- func (c *Client) BlockByNumber(ctx context.Context, number types.BlockNumber, full bool) (*types.Block, error)
- func (c *Client) BlockNumber(ctx context.Context) (*big.Int, error)
- func (c *Client) Call(ctx context.Context, call types.Call, block types.BlockNumber) ([]byte, error)
- func (c *Client) ChainID(ctx context.Context) (uint64, error)
- func (c *Client) EstimateGas(ctx context.Context, call types.Call, block types.BlockNumber) (uint64, error)
- func (c *Client) GasPrice(ctx context.Context) (*big.Int, error)
- func (c *Client) GetBalance(ctx context.Context, address types.Address, block types.BlockNumber) (*big.Int, error)
- func (c *Client) GetBlockTransactionCountByHash(ctx context.Context, hash types.Hash) (uint64, error)
- func (c *Client) GetBlockTransactionCountByNumber(ctx context.Context, number types.BlockNumber) (uint64, error)
- func (c *Client) GetCode(ctx context.Context, account types.Address, block types.BlockNumber) ([]byte, error)
- func (c *Client) GetLogs(ctx context.Context, query types.FilterLogsQuery) ([]types.Log, error)
- func (c *Client) GetStorageAt(ctx context.Context, account types.Address, key types.Hash, ...) (*types.Hash, error)
- func (c *Client) GetTransactionByBlockHashAndIndex(ctx context.Context, hash types.Hash, index uint64) (*types.OnChainTransaction, error)
- func (c *Client) GetTransactionByBlockNumberAndIndex(ctx context.Context, number types.BlockNumber, index uint64) (*types.OnChainTransaction, error)
- func (c *Client) GetTransactionByHash(ctx context.Context, hash types.Hash) (*types.OnChainTransaction, error)
- func (c *Client) GetTransactionCount(ctx context.Context, account types.Address, block types.BlockNumber) (uint64, error)
- func (c *Client) GetTransactionReceipt(ctx context.Context, hash types.Hash) (*types.TransactionReceipt, error)
- func (c *Client) GetUncleCountByBlockHash(ctx context.Context, hash types.Hash) (uint64, error)
- func (c *Client) GetUncleCountByBlockNumber(ctx context.Context, number types.BlockNumber) (uint64, error)
- func (c *Client) MaxPriorityFeePerGas(ctx context.Context) (*big.Int, error)
- func (c *Client) SendRawTransaction(ctx context.Context, data []byte) (*types.Hash, error)
- func (c *Client) SendTransaction(ctx context.Context, tx types.Transaction) (*types.Hash, error)
- func (c *Client) Sign(ctx context.Context, account types.Address, data []byte) (*types.Signature, error)
- func (c *Client) SignTransaction(ctx context.Context, tx types.Transaction) ([]byte, *types.Transaction, error)
- func (c *Client) SubscribeLogs(ctx context.Context, query types.FilterLogsQuery) (chan types.Log, error)
- func (c *Client) SubscribeNewHeads(ctx context.Context) (chan types.Block, error)
- func (c *Client) SubscribeNewPendingTransactions(ctx context.Context) (chan types.Hash, error)
- type ClientOptions
- type RPC
- type TXModifier
- type TXModifierFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client allows to interact with the Ethereum node.
func NewClient ¶
func NewClient(opts ...ClientOptions) (*Client, error)
NewClient creates a new RPC client. The WithTransport option is required.
func (*Client) BlockByHash ¶
BlockByHash implements the RPC interface.
func (*Client) BlockByNumber ¶
func (c *Client) BlockByNumber(ctx context.Context, number types.BlockNumber, full bool) (*types.Block, error)
BlockByNumber implements the RPC interface.
func (*Client) BlockNumber ¶
BlockNumber implements the RPC interface.
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, call types.Call, block types.BlockNumber) ([]byte, error)
Call implements the RPC interface.
func (*Client) EstimateGas ¶
func (c *Client) EstimateGas(ctx context.Context, call types.Call, block types.BlockNumber) (uint64, error)
EstimateGas implements the RPC interface.
func (*Client) GetBalance ¶
func (c *Client) GetBalance(ctx context.Context, address types.Address, block types.BlockNumber) (*big.Int, error)
GetBalance implements the RPC interface.
func (*Client) GetBlockTransactionCountByHash ¶
func (c *Client) GetBlockTransactionCountByHash(ctx context.Context, hash types.Hash) (uint64, error)
GetBlockTransactionCountByHash implements the RPC interface.
func (*Client) GetBlockTransactionCountByNumber ¶
func (c *Client) GetBlockTransactionCountByNumber(ctx context.Context, number types.BlockNumber) (uint64, error)
GetBlockTransactionCountByNumber implements the RPC interface.
func (*Client) GetCode ¶
func (c *Client) GetCode(ctx context.Context, account types.Address, block types.BlockNumber) ([]byte, error)
GetCode implements the RPC interface.
func (*Client) GetStorageAt ¶
func (c *Client) GetStorageAt(ctx context.Context, account types.Address, key types.Hash, block types.BlockNumber) (*types.Hash, error)
GetStorageAt implements the RPC interface.
func (*Client) GetTransactionByBlockHashAndIndex ¶
func (c *Client) GetTransactionByBlockHashAndIndex(ctx context.Context, hash types.Hash, index uint64) (*types.OnChainTransaction, error)
GetTransactionByBlockHashAndIndex implements the RPC interface.
func (*Client) GetTransactionByBlockNumberAndIndex ¶
func (c *Client) GetTransactionByBlockNumberAndIndex(ctx context.Context, number types.BlockNumber, index uint64) (*types.OnChainTransaction, error)
GetTransactionByBlockNumberAndIndex implements the RPC interface.
func (*Client) GetTransactionByHash ¶
func (c *Client) GetTransactionByHash(ctx context.Context, hash types.Hash) (*types.OnChainTransaction, error)
GetTransactionByHash implements the RPC interface.
func (*Client) GetTransactionCount ¶
func (c *Client) GetTransactionCount(ctx context.Context, account types.Address, block types.BlockNumber) (uint64, error)
GetTransactionCount implements the RPC interface.
func (*Client) GetTransactionReceipt ¶
func (c *Client) GetTransactionReceipt(ctx context.Context, hash types.Hash) (*types.TransactionReceipt, error)
GetTransactionReceipt implements the RPC interface.
func (*Client) GetUncleCountByBlockHash ¶
GetUncleCountByBlockHash implements the RPC interface.
func (*Client) GetUncleCountByBlockNumber ¶
func (c *Client) GetUncleCountByBlockNumber(ctx context.Context, number types.BlockNumber) (uint64, error)
GetUncleCountByBlockNumber implements the RPC interface.
func (*Client) MaxPriorityFeePerGas ¶
MaxPriorityFeePerGas implements the RPC interface.
func (*Client) SendRawTransaction ¶
SendRawTransaction implements the RPC interface.
func (*Client) SendTransaction ¶
SendTransaction implements the RPC interface.
func (*Client) Sign ¶
func (c *Client) Sign(ctx context.Context, account types.Address, data []byte) (*types.Signature, error)
Sign implements the RPC interface.
func (*Client) SignTransaction ¶
func (c *Client) SignTransaction(ctx context.Context, tx types.Transaction) ([]byte, *types.Transaction, error)
SignTransaction implements the RPC interface.
func (*Client) SubscribeLogs ¶
func (c *Client) SubscribeLogs(ctx context.Context, query types.FilterLogsQuery) (chan types.Log, error)
SubscribeLogs implements the RPC interface.
func (*Client) SubscribeNewHeads ¶
SubscribeNewHeads implements the RPC interface.
type ClientOptions ¶
func WithChainID ¶
func WithChainID(chainID uint64) ClientOptions
WithChainID sets the transaction.ChainID if it is not set in the following methods: - SignTransaction - SendTransaction
If the transaction has a ChainID set, it will return an error if it does not match the provided chain ID.
func WithDefaultAddress ¶
func WithDefaultAddress(addr types.Address) ClientOptions
WithDefaultAddress sets the transaction.From address if it is not set in the following methods: - SignTransaction - SendTransaction
func WithKeys ¶
func WithKeys(keys ...wallet.Key) ClientOptions
WithKeys allows to set keys that will be used to sign data. It allows to emulate the behavior of the RPC methods that require a key to be available in the node.
The following methods are affected:
- Accounts - returns the addresses of the provided keys
- Sign - signs the data with the provided key
- SignTransaction - signs transaction with the provided key
- SendTransaction - signs transaction with the provided key and sends it using SendRawTransaction
func WithTXModifiers ¶ added in v0.3.1
func WithTXModifiers(modifiers ...TXModifier) ClientOptions
WithTXModifiers allows to modify the transaction before it is signed and sent to the node.
Modifiers will be applied in the order they are provided.
func WithTransport ¶
func WithTransport(transport transport.Transport) ClientOptions
WithTransport sets the transport for the client.
type RPC ¶
type RPC interface { // ChainID performs eth_chainId RPC call. // // It returns the current chain ID. ChainID(ctx context.Context) (uint64, error) // GasPrice performs eth_gasPrice RPC call. // // It returns the current price per gas in wei. GasPrice(ctx context.Context) (*big.Int, error) // Accounts performs eth_accounts RPC call. // // It returns the list of addresses owned by the client. Accounts(ctx context.Context) ([]types.Address, error) // BlockNumber performs eth_blockNumber RPC call. // // It returns the current block number. BlockNumber(ctx context.Context) (*big.Int, error) // GetBalance performs eth_getBalance RPC call. // // It returns the balance of the account of given address in wei. GetBalance(ctx context.Context, address types.Address, block types.BlockNumber) (*big.Int, error) // GetStorageAt performs eth_getStorageAt RPC call. // // It returns the value of key in the contract storage at the given // address. GetStorageAt(ctx context.Context, account types.Address, key types.Hash, block types.BlockNumber) (*types.Hash, error) // GetTransactionCount performs eth_getTransactionCount RPC call. // // It returns the number of transactions sent from the given address. GetTransactionCount(ctx context.Context, account types.Address, block types.BlockNumber) (uint64, error) // GetBlockTransactionCountByHash performs eth_getBlockTransactionCountByHash RPC call. // // It returns the number of transactions in the block with the given hash. GetBlockTransactionCountByHash(ctx context.Context, hash types.Hash) (uint64, error) // GetBlockTransactionCountByNumber performs eth_getBlockTransactionCountByNumber RPC call. // // It returns the number of transactions in the block with the given block GetBlockTransactionCountByNumber(ctx context.Context, number types.BlockNumber) (uint64, error) // GetUncleCountByBlockHash performs eth_getUncleCountByBlockHash RPC call. // // It returns the number of uncles in the block with the given hash. GetUncleCountByBlockHash(ctx context.Context, hash types.Hash) (uint64, error) // GetUncleCountByBlockNumber performs eth_getUncleCountByBlockNumber RPC call. // // It returns the number of uncles in the block with the given block number. GetUncleCountByBlockNumber(ctx context.Context, number types.BlockNumber) (uint64, error) // GetCode performs eth_getCode RPC call. // // It returns the contract code at the given address. GetCode(ctx context.Context, account types.Address, block types.BlockNumber) ([]byte, error) // Sign performs eth_sign RPC call. // // It signs the given data with the given address. Sign(ctx context.Context, account types.Address, data []byte) (*types.Signature, error) // SignTransaction performs eth_signTransaction RPC call. // // It signs the given transaction. SignTransaction(ctx context.Context, tx types.Transaction) ([]byte, *types.Transaction, error) // SendTransaction performs eth_sendTransaction RPC call. // // It creates new message call transaction or a contract creation for // signed transactions. SendTransaction(ctx context.Context, tx types.Transaction) (*types.Hash, error) // SendRawTransaction performs eth_sendRawTransaction RPC call. // // It sends an encoded transaction to the network. SendRawTransaction(ctx context.Context, data []byte) (*types.Hash, error) // Call performs eth_call RPC call. // // Creates new message call transaction or a contract creation, if the data // field contains code. Call(ctx context.Context, call types.Call, block types.BlockNumber) ([]byte, error) // EstimateGas performs eth_estimateGas RPC call. // // It estimates the gas necessary to execute a specific transaction. EstimateGas(ctx context.Context, call types.Call, block types.BlockNumber) (uint64, error) // BlockByHash performs eth_getBlockByHash RPC call. // // It returns information about a block by hash. BlockByHash(ctx context.Context, hash types.Hash, full bool) (*types.Block, error) // BlockByNumber performs eth_getBlockByNumber RPC call. // // It returns the block with the given number. BlockByNumber(ctx context.Context, number types.BlockNumber, full bool) (*types.Block, error) // GetTransactionByHash performs eth_getTransactionByHash RPC call. // // It returns the information about a transaction requested by transaction. GetTransactionByHash(ctx context.Context, hash types.Hash) (*types.OnChainTransaction, error) // GetTransactionByBlockHashAndIndex performs eth_getTransactionByBlockHashAndIndex RPC call. // // It returns the information about a transaction requested by transaction. GetTransactionByBlockHashAndIndex(ctx context.Context, hash types.Hash, index uint64) (*types.OnChainTransaction, error) // GetTransactionByBlockNumberAndIndex performs eth_getTransactionByBlockNumberAndIndex RPC call. // // It returns the information about a transaction requested by transaction. GetTransactionByBlockNumberAndIndex(ctx context.Context, number types.BlockNumber, index uint64) (*types.OnChainTransaction, error) // GetTransactionReceipt performs eth_getTransactionReceipt RPC call. // // It returns the receipt of a transaction by transaction hash. GetTransactionReceipt(ctx context.Context, hash types.Hash) (*types.TransactionReceipt, error) // GetLogs performs eth_getLogs RPC call. // // It returns logs that match the given query. GetLogs(ctx context.Context, query types.FilterLogsQuery) ([]types.Log, error) // MaxPriorityFeePerGas performs eth_maxPriorityFeePerGas RPC call. // // It returns the estimated maximum priority fee per gas. MaxPriorityFeePerGas(ctx context.Context) (*big.Int, error) // SubscribeLogs performs eth_subscribe RPC call with "logs" subscription // type. // // It creates a subscription that will send logs that match the given query. // // Subscription channel will be closed when the context is canceled. SubscribeLogs(ctx context.Context, query types.FilterLogsQuery) (chan types.Log, error) // SubscribeNewHeads performs eth_subscribe RPC call with "newHeads" // subscription type. // // It creates a subscription that will send new block headers. // // Subscription channel will be closed when the context is canceled. SubscribeNewHeads(ctx context.Context) (chan types.Block, error) // SubscribeNewPendingTransactions performs eth_subscribe RPC call with // "newPendingTransactions" subscription type. // // It creates a subscription that will send new pending transactions. // // Subscription channel will be closed when the context is canceled. SubscribeNewPendingTransactions(ctx context.Context) (chan types.Hash, error) }
RPC is an RPC client for the Ethereum-compatible nodes.
type TXModifier ¶ added in v0.3.1
TXModifier allows to modify the transaction before it is signed or sent to the node.
type TXModifierFunc ¶ added in v0.3.1
func (TXModifierFunc) Modify ¶ added in v0.3.1
func (f TXModifierFunc) Modify(ctx context.Context, client RPC, tx *types.Transaction) error