jsonrpc

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBig

func DecodeBig(s string) (*big.Int, error)

DecodeBig decodes either - a hex with 0x prefix - a decimal - "" (decoded to <nil>)

func EncodeBig

func EncodeBig(b *big.Int) string

EncodeBig encodes either - >0 to a hex with 0x prefix - <0 to a hex with -0x prefix - <nil> to ""

func FromBlockNumArg

func FromBlockNumArg(s string) (*big.Int, error)

FromBlockNumArg decodes a string into a big.Int block number

func Has0xPrefix

func Has0xPrefix(input string) bool

Has0xPrefix returns either input starts with a 0x prefix

func MustFromBlockNumArg

func MustFromBlockNumArg(s string) *big.Int

func ToBlockNumArg

func ToBlockNumArg(number *big.Int) string

ToBlockNumArg transforms a big.Int into a block string representation

Types

type Client

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

Client provides methods to interface with a JSON-RPC Ethereum Execution node

func NewFromClient

func NewFromClient(cli jsonrpc.Client) *Client

New creates a new client

func (*Client) BalanceAt

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

func (*Client) BlockByHash

func (c *Client) BlockByHash(ctx context.Context, hash gethcommon.Hash) (*gethtypes.Block, error)

BlockByHash returns the given full block.

Note fetch of uncles blocks is not implemented yet.

func (*Client) BlockByNumber

func (c *Client) BlockByNumber(ctx context.Context, blockNumber *big.Int) (*gethtypes.Block, error)

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

Note fetch of uncles blocks is not implemented yet.

func (*Client) BlockNumber

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

BlockNumber returns current chain head number

func (*Client) CallContract

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

CallContract executes contract call The block number can be nil, in which case call is executed at the latest block.

func (*Client) CallContractAtHash

func (c *Client) CallContractAtHash(ctx context.Context, msg geth.CallMsg, blockHash gethcommon.Hash) ([]byte, error)

CallContractAtHash is almost the same as CallContract except that it selects the block by block hash instead of block height.

func (*Client) ChainID

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

ChainID retrieves the current chain ID

func (*Client) CodeAt

func (c *Client) CodeAt(ctx context.Context, account gethcommon.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 block.

func (*Client) EstimateGas

func (c *Client) EstimateGas(ctx context.Context, msg geth.CallMsg) (uint64, error)

EstimateGas tries to estimate the gas needed to execute a specific transaction based on the current pending state of the chain.

func (*Client) FeeHistory

func (c *Client) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*geth.FeeHistory, error)

FeeHistory retrieves the fee market history.

func (*Client) FilterLogs

func (c *Client) FilterLogs(ctx context.Context, q geth.FilterQuery) ([]gethtypes.Log, error)

FilterLogs executes a filter query.

func (*Client) GetProof

func (c *Client) GetProof(ctx context.Context, account gethcommon.Address, keys []string, blockNumber *big.Int) (*gethclient.AccountResult, error)

GetProof returns the account and storage values of the specified account including the Merkle-proof. The block number can be nil, in which case the value is taken from the latest known block.

func (*Client) HeaderByHash

func (c *Client) HeaderByHash(ctx context.Context, hash gethcommon.Hash) (*gethtypes.Header, error)

HeaderByNumber returns header of a given block hash

func (*Client) HeaderByNumber

func (c *Client) HeaderByNumber(ctx context.Context, blockNumber *big.Int) (*gethtypes.Header, error)

HeaderByNumber returns header of a given block number

func (*Client) NetworkID

func (c *Client) NetworkID(ctx context.Context) (*big.Int, error)

NetworkID returns the network ID (also known as the chain ID) for this chain.

func (*Client) NonceAt

func (c *Client) NonceAt(ctx context.Context, account gethcommon.Address, blockNumber *big.Int) (uint64, error)

NonceAt returns the next nonce for the given account. The block number can be nil, in which case the code is taken from the latest block.

func (*Client) PeerCount

func (c *Client) PeerCount(ctx context.Context) (uint64, error)

PeerCount returns the number of p2p peers as reported by the net_peerCount method.

func (*Client) PendingBalanceAt

func (c *Client) PendingBalanceAt(ctx context.Context, account gethcommon.Address) (*big.Int, error)

PendingBalanceAt returns the wei balance of the given account in the pending state.

func (*Client) PendingCallContract

func (c *Client) PendingCallContract(ctx context.Context, msg geth.CallMsg) ([]byte, error)

PendingCallContract executes a message call transaction using the EVM. The state seen by the contract call is the pending state.

func (*Client) PendingCodeAt

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

PendingCodeAt returns the contract code of the given account on pending state

func (*Client) PendingNonceAt

func (c *Client) PendingNonceAt(ctx context.Context, account gethcommon.Address) (uint64, error)

PendingNonceAt returns the next nonce for the given account considering pending transaction.

func (*Client) PendingStorageAt

func (c *Client) PendingStorageAt(ctx context.Context, account gethcommon.Address, key gethcommon.Hash) ([]byte, error)

PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.

func (*Client) PendingTransactionCount

func (c *Client) PendingTransactionCount(ctx context.Context) (uint, error)

PendingTransactionCount returns the total number of transactions in the pending state.

func (*Client) SendTransaction

func (c *Client) SendTransaction(ctx context.Context, tx *gethtypes.Transaction) error

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

func (*Client) StorageAt

func (c *Client) StorageAt(ctx context.Context, account gethcommon.Address, key gethcommon.Hash, blockNumber *big.Int) ([]byte, error)

StorageAt returns the value of key in the contract storage of the given account. The block number can be nil, in which case the value is taken from the latest known block.

func (*Client) SubscribeFilterLogs

func (c *Client) SubscribeFilterLogs(_ context.Context, _ geth.FilterQuery, _ chan<- gethtypes.Log) (geth.Subscription, error)

SubscribeFilterLogs subscribes to the results of a streaming filter query.

func (*Client) SubscribeNewHead

func (c *Client) SubscribeNewHead(_ context.Context, _ chan<- *gethtypes.Header) (geth.Subscription, error)

func (*Client) SuggestGasPrice

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

SuggestGasPrice returns gas price for a transaction to be included in a miner block in a timely manner considering current network activity

func (*Client) SuggestGasTipCap

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

SuggestGasPrice returns a gas tip cap after EIP-1559 for a transaction to be included in a miner block in a timely manner considering current network activity

func (*Client) SyncProgress

func (c *Client) SyncProgress(_ context.Context) (*geth.SyncProgress, error)

func (*Client) TransactionByHash

func (c *Client) TransactionByHash(ctx context.Context, hash gethcommon.Hash) (tx *gethtypes.Transaction, isPending bool, err error)

TransactionByHash returns the transaction with the given hash.

func (*Client) TransactionCount

func (c *Client) TransactionCount(ctx context.Context, blockHash gethcommon.Hash) (uint, error)

TransactionCount returns the total number of transactions in the given block.

func (*Client) TransactionInBlock

func (c *Client) TransactionInBlock(ctx context.Context, blockHash gethcommon.Hash, index uint) (*gethtypes.Transaction, error)

TransactionInBlock returns a single transaction at index in the given block.

func (*Client) TransactionReceipt

func (c *Client) TransactionReceipt(ctx context.Context, txHash gethcommon.Hash) (*gethtypes.Receipt, error)

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

func (*Client) TransactionSender

func (c *Client) TransactionSender(ctx context.Context, tx *gethtypes.Transaction, block gethcommon.Hash, index uint) (gethcommon.Address, error)

TransactionSender returns the sender address of the given transaction. The transaction must be known to the remote node and included in the blockchain at the given block and index. The sender is the one derived by the protocol at the time of inclusion.

There is a fast-path for transactions retrieved by TransactionByHash and TransactionInBlock. Getting their sender address can be done without an RPC interaction.

Jump to

Keyboard shortcuts

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