Documentation
¶
Overview ¶
Package node provides the Node API client for JSON-RPC methods.
Index ¶
- type AccountProof
- type BlockNumberOrTag
- type CallMsg
- type Client
- func (c *Client) BlobBaseFee(ctx context.Context) (*big.Int, error)
- func (c *Client) BlockNumber(ctx context.Context) (uint64, error)
- func (c *Client) Call(ctx context.Context, msg *CallMsg, block BlockNumberOrTag) ([]byte, error)
- func (c *Client) ChainID(ctx context.Context) (uint64, error)
- func (c *Client) EstimateGas(ctx context.Context, msg *CallMsg) (uint64, error)
- func (c *Client) FeeHistory(ctx context.Context, blockCount uint64, newestBlock BlockNumberOrTag, ...) (*FeeHistory, error)
- func (c *Client) GasPrice(ctx context.Context) (*big.Int, error)
- func (c *Client) GetBalance(ctx context.Context, address types.Address, block BlockNumberOrTag) (*big.Int, error)
- func (c *Client) GetBlockByHash(ctx context.Context, hash types.Hash, fullTx bool) (*types.Block, error)
- func (c *Client) GetBlockByNumber(ctx context.Context, number BlockNumberOrTag, fullTx bool) (*types.Block, error)
- func (c *Client) GetBlockReceipts(ctx context.Context, block BlockNumberOrTag) ([]types.TransactionReceipt, error)
- func (c *Client) GetBlockTransactionCountByHash(ctx context.Context, hash types.Hash) (uint64, error)
- func (c *Client) GetBlockTransactionCountByNumber(ctx context.Context, number BlockNumberOrTag) (uint64, error)
- func (c *Client) GetCode(ctx context.Context, address types.Address, block BlockNumberOrTag) ([]byte, error)
- func (c *Client) GetLogs(ctx context.Context, filter *LogFilter) ([]types.Log, error)
- func (c *Client) GetProof(ctx context.Context, address types.Address, storageKeys []types.Hash, ...) (*AccountProof, error)
- func (c *Client) GetStorageAt(ctx context.Context, address types.Address, slot types.Hash, ...) (types.Hash, error)
- func (c *Client) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash types.Hash, index uint64) (*types.Transaction, error)
- func (c *Client) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNumber BlockNumberOrTag, index uint64) (*types.Transaction, error)
- func (c *Client) GetTransactionByHash(ctx context.Context, hash types.Hash) (*types.Transaction, error)
- func (c *Client) GetTransactionCount(ctx context.Context, address types.Address, block BlockNumberOrTag) (uint64, error)
- func (c *Client) GetTransactionReceipt(ctx context.Context, hash types.Hash) (*types.TransactionReceipt, error)
- func (c *Client) MaxPriorityFeePerGas(ctx context.Context) (*big.Int, error)
- func (c *Client) RPC() *client.JSONRPCClient
- func (c *Client) SendRawTransaction(ctx context.Context, signedTx []byte) (types.Hash, error)
- func (c *Client) Syncing(ctx context.Context) (*SyncStatus, error)
- type FeeHistory
- type LogFilter
- func (f *LogFilter) SetAddress(address types.Address) *LogFilter
- func (f *LogFilter) SetAddresses(addresses []types.Address) *LogFilter
- func (f *LogFilter) SetBlockHash(hash types.Hash) *LogFilter
- func (f *LogFilter) SetBlockRange(from, to BlockNumberOrTag) *LogFilter
- func (f *LogFilter) SetFromBlock(block BlockNumberOrTag) *LogFilter
- func (f *LogFilter) SetToBlock(block BlockNumberOrTag) *LogFilter
- func (f *LogFilter) SetTopic0(topic types.Hash) *LogFilter
- func (f *LogFilter) SetTopic0Or(topics []types.Hash) *LogFilter
- func (f *LogFilter) SetTopic1(topic types.Hash) *LogFilter
- func (f *LogFilter) SetTopic2(topic types.Hash) *LogFilter
- func (f *LogFilter) SetTopic3(topic types.Hash) *LogFilter
- type StorageProof
- type SyncStatus
- type TraceConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountProof ¶
type AccountProof struct {
Address types.Address `json:"address"`
AccountProof []types.Data `json:"accountProof"`
Balance types.Quantity `json:"balance"`
CodeHash types.Hash `json:"codeHash"`
Nonce types.Quantity `json:"nonce"`
StorageHash types.Hash `json:"storageHash"`
StorageProof []StorageProof `json:"storageProof"`
}
AccountProof represents the result of eth_getProof.
type BlockNumberOrTag ¶
type BlockNumberOrTag string
BlockNumberOrTag represents a block number or a special tag.
const ( BlockLatest BlockNumberOrTag = "latest" BlockPending BlockNumberOrTag = "pending" BlockEarliest BlockNumberOrTag = "earliest" BlockFinalized BlockNumberOrTag = "finalized" BlockSafe BlockNumberOrTag = "safe" )
Block number tags.
func BlockNumber ¶
func BlockNumber(n uint64) BlockNumberOrTag
BlockNumber creates a BlockNumberOrTag from a block number.
func BlockNumberFromBigInt ¶
func BlockNumberFromBigInt(n *big.Int) BlockNumberOrTag
BlockNumberFromBigInt creates a BlockNumberOrTag from a *big.Int.
func (BlockNumberOrTag) IsTag ¶
func (b BlockNumberOrTag) IsTag() bool
IsTag returns true if this is a special tag (latest, pending, etc.).
func (BlockNumberOrTag) MarshalJSON ¶
func (b BlockNumberOrTag) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (BlockNumberOrTag) String ¶
func (b BlockNumberOrTag) String() string
String returns the string representation.
func (BlockNumberOrTag) Uint64 ¶
func (b BlockNumberOrTag) Uint64() uint64
Uint64 returns the block number as uint64. Returns 0 if this is a tag.
func (*BlockNumberOrTag) UnmarshalJSON ¶
func (b *BlockNumberOrTag) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type CallMsg ¶
type CallMsg struct {
// From is the sender address.
From *types.Address `json:"from,omitempty"`
// To is the recipient address (contract address).
To *types.Address `json:"to,omitempty"`
// Gas is the gas limit.
Gas *uint64 `json:"gas,omitempty"`
// GasPrice is the gas price (legacy).
GasPrice *big.Int `json:"gasPrice,omitempty"`
// MaxFeePerGas is the max fee per gas (EIP-1559).
MaxFeePerGas *big.Int `json:"maxFeePerGas,omitempty"`
// MaxPriorityFeePerGas is the max priority fee per gas (EIP-1559).
MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas,omitempty"`
// Value is the value to send.
Value *big.Int `json:"value,omitempty"`
// Data is the input data.
Data []byte `json:"data,omitempty"`
}
CallMsg represents a contract call message.
func (CallMsg) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Node API client for making JSON-RPC calls.
func NewClient ¶
func NewClient(rpc *client.JSONRPCClient) *Client
NewClient creates a new Node API client.
func (*Client) BlobBaseFee ¶
BlobBaseFee returns the current blob base fee.
func (*Client) BlockNumber ¶
BlockNumber returns the current block number.
func (*Client) EstimateGas ¶
EstimateGas estimates the gas needed for a transaction.
func (*Client) FeeHistory ¶
func (c *Client) FeeHistory(ctx context.Context, blockCount uint64, newestBlock BlockNumberOrTag, rewardPercentiles []float64) (*FeeHistory, error)
FeeHistory returns historical gas fee data.
func (*Client) GetBalance ¶
func (c *Client) GetBalance(ctx context.Context, address types.Address, block BlockNumberOrTag) (*big.Int, error)
GetBalance returns the balance of the given address at the given block.
func (*Client) GetBlockByHash ¶
func (c *Client) GetBlockByHash(ctx context.Context, hash types.Hash, fullTx bool) (*types.Block, error)
GetBlockByHash returns a block by its hash.
func (*Client) GetBlockByNumber ¶
func (c *Client) GetBlockByNumber(ctx context.Context, number BlockNumberOrTag, fullTx bool) (*types.Block, error)
GetBlockByNumber returns a block by its number.
func (*Client) GetBlockReceipts ¶
func (c *Client) GetBlockReceipts(ctx context.Context, block BlockNumberOrTag) ([]types.TransactionReceipt, error)
GetBlockReceipts returns all transaction receipts for a block.
func (*Client) GetBlockTransactionCountByHash ¶
func (c *Client) GetBlockTransactionCountByHash(ctx context.Context, hash types.Hash) (uint64, error)
GetBlockTransactionCountByHash returns the number of transactions in a block by its hash.
func (*Client) GetBlockTransactionCountByNumber ¶
func (c *Client) GetBlockTransactionCountByNumber(ctx context.Context, number BlockNumberOrTag) (uint64, error)
GetBlockTransactionCountByNumber returns the number of transactions in a block by its number.
func (*Client) GetCode ¶
func (c *Client) GetCode(ctx context.Context, address types.Address, block BlockNumberOrTag) ([]byte, error)
GetCode returns the code at the given address at the given block.
func (*Client) GetProof ¶
func (c *Client) GetProof(ctx context.Context, address types.Address, storageKeys []types.Hash, block BlockNumberOrTag) (*AccountProof, error)
GetProof returns the account and storage values with Merkle proof.
func (*Client) GetStorageAt ¶
func (c *Client) GetStorageAt(ctx context.Context, address types.Address, slot types.Hash, block BlockNumberOrTag) (types.Hash, error)
GetStorageAt returns the value of a storage slot at the given address.
func (*Client) GetTransactionByBlockHashAndIndex ¶
func (c *Client) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash types.Hash, index uint64) (*types.Transaction, error)
GetTransactionByBlockHashAndIndex returns a transaction by block hash and index.
func (*Client) GetTransactionByBlockNumberAndIndex ¶
func (c *Client) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNumber BlockNumberOrTag, index uint64) (*types.Transaction, error)
GetTransactionByBlockNumberAndIndex returns a transaction by block number and index.
func (*Client) GetTransactionByHash ¶
func (c *Client) GetTransactionByHash(ctx context.Context, hash types.Hash) (*types.Transaction, error)
GetTransactionByHash returns a transaction by its hash.
func (*Client) GetTransactionCount ¶
func (c *Client) GetTransactionCount(ctx context.Context, address types.Address, block BlockNumberOrTag) (uint64, error)
GetTransactionCount returns the nonce of the given address at the given block.
func (*Client) GetTransactionReceipt ¶
func (c *Client) GetTransactionReceipt(ctx context.Context, hash types.Hash) (*types.TransactionReceipt, error)
GetTransactionReceipt returns a transaction receipt by its hash.
func (*Client) MaxPriorityFeePerGas ¶
MaxPriorityFeePerGas returns the current max priority fee per gas.
func (*Client) RPC ¶
func (c *Client) RPC() *client.JSONRPCClient
RPC returns the underlying JSON-RPC client.
func (*Client) SendRawTransaction ¶
SendRawTransaction sends a signed transaction.
type FeeHistory ¶
type FeeHistory struct {
// OldestBlock is the oldest block in the range.
OldestBlock types.Quantity `json:"oldestBlock"`
// BaseFeePerGas is the base fee per gas for each block.
BaseFeePerGas []types.Quantity `json:"baseFeePerGas"`
// GasUsedRatio is the ratio of gas used to gas limit for each block.
GasUsedRatio []float64 `json:"gasUsedRatio"`
// Reward is the priority fee per gas percentiles for each block.
Reward [][]types.Quantity `json:"reward,omitempty"`
// BaseFeePerBlobGas is the base fee per blob gas for each block (EIP-4844).
BaseFeePerBlobGas []types.Quantity `json:"baseFeePerBlobGas,omitempty"`
// BlobGasUsedRatio is the ratio of blob gas used for each block (EIP-4844).
BlobGasUsedRatio []float64 `json:"blobGasUsedRatio,omitempty"`
}
FeeHistory represents the result of eth_feeHistory.
type LogFilter ¶
type LogFilter struct {
// FromBlock is the starting block (inclusive).
FromBlock BlockNumberOrTag `json:"fromBlock,omitempty"`
// ToBlock is the ending block (inclusive).
ToBlock BlockNumberOrTag `json:"toBlock,omitempty"`
// Address filters logs by contract address.
Address interface{} `json:"address,omitempty"` // string or []string
// Topics filters logs by topics.
Topics []interface{} `json:"topics,omitempty"` // each element is string or []string or nil
// BlockHash filters logs from a specific block (mutually exclusive with FromBlock/ToBlock).
BlockHash *types.Hash `json:"blockHash,omitempty"`
}
LogFilter represents a filter for eth_getLogs.
func (*LogFilter) SetAddress ¶
SetAddress sets a single address filter.
func (*LogFilter) SetAddresses ¶
SetAddresses sets multiple address filters.
func (*LogFilter) SetBlockHash ¶
SetBlockHash sets a specific block hash filter.
func (*LogFilter) SetBlockRange ¶
func (f *LogFilter) SetBlockRange(from, to BlockNumberOrTag) *LogFilter
SetBlockRange sets both from and to blocks.
func (*LogFilter) SetFromBlock ¶
func (f *LogFilter) SetFromBlock(block BlockNumberOrTag) *LogFilter
SetFromBlock sets the starting block.
func (*LogFilter) SetToBlock ¶
func (f *LogFilter) SetToBlock(block BlockNumberOrTag) *LogFilter
SetToBlock sets the ending block.
func (*LogFilter) SetTopic0Or ¶
SetTopic0Or sets the first topic to match any of the given topics.
type StorageProof ¶
type StorageProof struct {
Key types.Hash `json:"key"`
Value types.Quantity `json:"value"`
Proof []types.Data `json:"proof"`
}
StorageProof represents a storage proof.
type SyncStatus ¶
type SyncStatus struct {
// Syncing is true if the node is syncing.
Syncing bool
// StartingBlock is the block at which the sync started.
StartingBlock uint64
// CurrentBlock is the current block being synced.
CurrentBlock uint64
// HighestBlock is the highest known block.
HighestBlock uint64
}
SyncStatus represents the result of eth_syncing.
func (*SyncStatus) UnmarshalJSON ¶
func (s *SyncStatus) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type TraceConfig ¶
type TraceConfig struct {
// DisableStorage disables storage capture.
DisableStorage bool `json:"disableStorage,omitempty"`
// DisableStack disables stack capture.
DisableStack bool `json:"disableStack,omitempty"`
// EnableMemory enables memory capture.
EnableMemory bool `json:"enableMemory,omitempty"`
// EnableReturnData enables return data capture.
EnableReturnData bool `json:"enableReturnData,omitempty"`
// Tracer is the name of a built-in tracer.
Tracer string `json:"tracer,omitempty"`
// TracerConfig is configuration for the tracer.
TracerConfig json.RawMessage `json:"tracerConfig,omitempty"`
// Timeout is the maximum time for tracing.
Timeout string `json:"timeout,omitempty"`
}
TraceConfig represents configuration for trace methods.