Documentation ¶
Index ¶
- Constants
- Variables
- func NameHash(name string) (hash [32]byte, err error)
- func Normalize(input string) (output string, err error)
- func ResolveEnsAddress(ctx context.Context, ens string, provider *Provider) (common.Address, bool, error)
- func WaitForTxnReceipt(ctx context.Context, provider *Provider, txHash common.Hash) (*types.Receipt, error)
- type BatchCall
- type BatchError
- type Call
- type CallBuilder
- func BalanceAt(account common.Address, blockNum *big.Int) CallBuilder[*big.Int]
- func BlockByHash(hash common.Hash) CallBuilder[*types.Block]
- func BlockByNumber(blockNum *big.Int) CallBuilder[*types.Block]
- func BlockNumber() CallBuilder[uint64]
- func BlockRange(startBlockNum, endBlockNum *big.Int) CallBuilder[[]*types.Block]
- func CallContract(msg ethereum.CallMsg, blockNum *big.Int) CallBuilder[[]byte]
- func CallContractAtHash(msg ethereum.CallMsg, blockHash common.Hash) CallBuilder[[]byte]
- func ChainID() CallBuilder[*big.Int]
- func CodeAt(account common.Address, blockNum *big.Int) CallBuilder[[]byte]
- func EstimateGas(msg ethereum.CallMsg) CallBuilder[uint64]
- func FeeHistory(blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) CallBuilder[*ethereum.FeeHistory]
- func FilterLogs(q ethereum.FilterQuery) CallBuilder[[]types.Log]
- func HeaderByHash(hash common.Hash) CallBuilder[*types.Header]
- func HeaderByNumber(blockNum *big.Int) CallBuilder[*types.Header]
- func NetworkID() CallBuilder[*big.Int]
- func NewCallBuilder[T any](method string, intoFn IntoFn[T], params ...any) CallBuilder[T]
- func NonceAt(account common.Address, blockNum *big.Int) CallBuilder[uint64]
- func PeerCount() CallBuilder[uint64]
- func PendingBalanceAt(account common.Address) CallBuilder[*big.Int]
- func PendingCallContract(msg ethereum.CallMsg) CallBuilder[[]byte]
- func PendingCodeAt(account common.Address) CallBuilder[[]byte]
- func PendingNonceAt(account common.Address) CallBuilder[uint64]
- func PendingStorageAt(account common.Address, key common.Hash) CallBuilder[[]byte]
- func PendingTransactionCount() CallBuilder[uint]
- func SendRawTransaction(signedTxHex string) CallBuilder[common.Hash]
- func StorageAt(account common.Address, key common.Hash, blockNum *big.Int) CallBuilder[[]byte]
- func SuggestGasPrice() CallBuilder[*big.Int]
- func SuggestGasTipCap() CallBuilder[*big.Int]
- func SyncProgress() CallBuilder[*ethereum.SyncProgress]
- func TransactionCount(blockHash common.Hash) CallBuilder[uint]
- func TransactionInBlock(blockHash common.Hash, index uint) CallBuilder[*types.Transaction]
- func TransactionReceipt(txHash common.Hash) CallBuilder[*types.Receipt]
- func TransactionSender(tx *types.Transaction, block common.Hash, index uint) CallBuilder[common.Address]
- type CallBuilder2
- type Interface
- type IntoFn
- type Network
- type Option
- type Provider
- func (p *Provider) BalanceAt(ctx context.Context, account common.Address, blockNum *big.Int) (*big.Int, error)
- func (p *Provider) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
- func (p *Provider) BlockByNumber(ctx context.Context, blockNum *big.Int) (*types.Block, error)
- func (p *Provider) BlockNumber(ctx context.Context) (uint64, error)
- func (p *Provider) BlockRange(ctx context.Context, startBlockNum, endBlockNum *big.Int) ([]*types.Block, error)
- func (p *Provider) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNum *big.Int) ([]byte, error)
- func (p *Provider) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
- func (p *Provider) ChainID(ctx context.Context) (*big.Int, error)
- func (p *Provider) CodeAt(ctx context.Context, account common.Address, blockNum *big.Int) ([]byte, error)
- func (p *Provider) ContractQuery(ctx context.Context, contractAddress string, ...) ([]string, error)
- func (p *Provider) Do(ctx context.Context, calls ...Call) error
- func (p *Provider) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
- func (p *Provider) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, ...) (*ethereum.FeeHistory, error)
- func (p *Provider) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
- func (p *Provider) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
- func (p *Provider) HeaderByNumber(ctx context.Context, blockNum *big.Int) (*types.Header, error)
- func (p *Provider) NetworkID(ctx context.Context) (*big.Int, error)
- func (p *Provider) NonceAt(ctx context.Context, account common.Address, blockNum *big.Int) (uint64, error)
- func (p *Provider) PeerCount(ctx context.Context) (uint64, error)
- func (p *Provider) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
- func (p *Provider) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
- func (p *Provider) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
- func (p *Provider) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
- func (p *Provider) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
- func (p *Provider) PendingTransactionCount(ctx context.Context) (uint, error)
- func (s *Provider) SendRawTransaction(ctx context.Context, signedTxHex string) (common.Hash, error)
- func (p *Provider) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (s *Provider) SetHTTPClient(httpClient *http.Client)
- func (p *Provider) StorageAt(ctx context.Context, account common.Address, key common.Hash, ...) ([]byte, error)
- func (p *Provider) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
- func (p *Provider) SuggestGasPrice(ctx context.Context) (*big.Int, error)
- func (p *Provider) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
- func (p *Provider) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
- func (p *Provider) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, pending bool, err error)
- func (p *Provider) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
- func (p *Provider) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
- func (p *Provider) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
- func (p *Provider) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
Examples ¶
Constants ¶
View Source
const ENSContractAddress = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"
Variables ¶
View Source
var ( ErrNotFound = ethereum.NotFound ErrEmptyResponse = errors.New("ethrpc: empty response") ErrUnsupportedMethodOnChain = errors.New("ethrpc: method is unsupported on this chain") ErrRequestFail = errors.New("ethrpc: request fail") )
View Source
var Networks = map[uint64]Network{
1: {
Name: "mainnet",
ChainID: 1,
NumBlocksToFinality: 20,
},
3: {
Name: "ropsten",
ChainID: 3,
NumBlocksToFinality: 20,
},
4: {
Name: "rinkeby",
ChainID: 4,
NumBlocksToFinality: 20,
},
5: {
Name: "goerli",
ChainID: 5,
NumBlocksToFinality: 20,
},
42: {
Name: "kovan",
ChainID: 42,
NumBlocksToFinality: 20,
},
137: {
Name: "polygon",
ChainID: 137,
NumBlocksToFinality: 100,
},
80001: {
Name: "polygon-mumbai",
ChainID: 80001,
NumBlocksToFinality: 100,
},
56: {
Name: "bsc",
ChainID: 56,
NumBlocksToFinality: 50,
},
97: {
Name: "bsc-testnet",
ChainID: 97,
NumBlocksToFinality: 50,
},
10: {
Name: "optimism",
ChainID: 10,
NumBlocksToFinality: 50,
},
69: {
Name: "optimism-testnet",
ChainID: 69,
NumBlocksToFinality: 50,
},
42161: {
Name: "arbitrum",
ChainID: 42161,
NumBlocksToFinality: 50,
},
421613: {
Name: "arbitrum-testnet",
ChainID: 421613,
NumBlocksToFinality: 50,
},
42170: {
Name: "arbitrum-nova",
ChainID: 42170,
NumBlocksToFinality: 50,
},
43114: {
Name: "avalanche",
ChainID: 43114,
NumBlocksToFinality: 50,
},
43113: {
Name: "avalanche-testnet",
ChainID: 43113,
NumBlocksToFinality: 50,
},
250: {
Name: "fantom",
ChainID: 250,
NumBlocksToFinality: 100,
},
4002: {
Name: "fantom-testnet",
ChainID: 4002,
NumBlocksToFinality: 100,
},
100: {
Name: "gnosis",
ChainID: 100,
NumBlocksToFinality: 100,
},
1313161554: {
Name: "aurora",
ChainID: 1313161554,
NumBlocksToFinality: 50,
},
1313161556: {
Name: "aurora-testnet",
ChainID: 1313161556,
NumBlocksToFinality: 50,
},
}
View Source
var Pending = big.NewInt(-1)
Functions ¶
func NameHash ¶ added in v1.17.8
NameHash generates a hash from a name that can be used to look up the name in ENS
func ResolveEnsAddress ¶ added in v1.17.8
Types ¶
type BatchCall ¶ added in v1.19.0
type BatchCall []*Call
Example ¶
package main import ( "context" "fmt" "math/big" "github.com/0xsequence/ethkit/ethrpc" "github.com/0xsequence/ethkit/go-ethereum/common" "github.com/0xsequence/ethkit/go-ethereum/core/types" ) func main() { p, err := ethrpc.NewProvider("https://nodes.sequence.app/polygon/test") if err != nil { panic(err) } var ( chainID *big.Int header *types.Header errBlock *types.Block ) err = p.Do( context.Background(), ethrpc.ChainID().Into(&chainID), ethrpc.HeaderByNumber(big.NewInt(38470000)).Into(&header), ethrpc.BlockByHash(common.BytesToHash([]byte("a1b2c3"))).Into(&errBlock), ) fmt.Printf("polygon ID: %s\n", chainID.String()) if err != nil { if batchErr, ok := err.(ethrpc.BatchError); ok { for i, err := range batchErr { fmt.Printf("error at %d: %s\n", i, err) } } } }
Output: polygon ID: 137 error at 2: not found
func (*BatchCall) ErrorOrNil ¶ added in v1.19.0
func (*BatchCall) MarshalJSON ¶ added in v1.19.0
func (*BatchCall) UnmarshalJSON ¶ added in v1.19.0
type BatchError ¶ added in v1.19.0
func (BatchError) Error ¶ added in v1.19.0
func (e BatchError) Error() string
func (BatchError) ErrorMap ¶ added in v1.19.0
func (e BatchError) ErrorMap() map[int]error
func (BatchError) Unwrap ¶ added in v1.19.0
func (e BatchError) Unwrap() error
type Call ¶ added in v1.19.0
type Call struct {
// contains filtered or unexported fields
}
func SendTransaction ¶ added in v1.19.0
func SendTransaction(tx *types.Transaction) Call
type CallBuilder ¶ added in v1.19.0
type CallBuilder[T any] struct { // contains filtered or unexported fields }
func BlockByHash ¶ added in v1.19.0
func BlockByHash(hash common.Hash) CallBuilder[*types.Block]
func BlockByNumber ¶ added in v1.19.0
func BlockByNumber(blockNum *big.Int) CallBuilder[*types.Block]
func BlockNumber ¶ added in v1.19.0
func BlockNumber() CallBuilder[uint64]
func BlockRange ¶ added in v1.19.0
func BlockRange(startBlockNum, endBlockNum *big.Int) CallBuilder[[]*types.Block]
func CallContract ¶ added in v1.19.0
func CallContract(msg ethereum.CallMsg, blockNum *big.Int) CallBuilder[[]byte]
func CallContractAtHash ¶ added in v1.19.0
func CallContractAtHash(msg ethereum.CallMsg, blockHash common.Hash) CallBuilder[[]byte]
func ChainID ¶ added in v1.19.0
func ChainID() CallBuilder[*big.Int]
func EstimateGas ¶ added in v1.19.0
func EstimateGas(msg ethereum.CallMsg) CallBuilder[uint64]
func FeeHistory ¶ added in v1.19.0
func FeeHistory(blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) CallBuilder[*ethereum.FeeHistory]
func FilterLogs ¶ added in v1.19.0
func FilterLogs(q ethereum.FilterQuery) CallBuilder[[]types.Log]
func HeaderByHash ¶ added in v1.19.0
func HeaderByHash(hash common.Hash) CallBuilder[*types.Header]
func HeaderByNumber ¶ added in v1.19.0
func HeaderByNumber(blockNum *big.Int) CallBuilder[*types.Header]
func NetworkID ¶ added in v1.19.0
func NetworkID() CallBuilder[*big.Int]
func NewCallBuilder ¶ added in v1.19.0
func NewCallBuilder[T any](method string, intoFn IntoFn[T], params ...any) CallBuilder[T]
func PeerCount ¶ added in v1.19.0
func PeerCount() CallBuilder[uint64]
func PendingBalanceAt ¶ added in v1.19.0
func PendingBalanceAt(account common.Address) CallBuilder[*big.Int]
func PendingCallContract ¶ added in v1.19.0
func PendingCallContract(msg ethereum.CallMsg) CallBuilder[[]byte]
func PendingCodeAt ¶ added in v1.19.0
func PendingCodeAt(account common.Address) CallBuilder[[]byte]
func PendingNonceAt ¶ added in v1.19.0
func PendingNonceAt(account common.Address) CallBuilder[uint64]
func PendingStorageAt ¶ added in v1.19.0
func PendingTransactionCount ¶ added in v1.19.0
func PendingTransactionCount() CallBuilder[uint]
func SendRawTransaction ¶ added in v1.19.0
func SendRawTransaction(signedTxHex string) CallBuilder[common.Hash]
func SuggestGasPrice ¶ added in v1.19.0
func SuggestGasPrice() CallBuilder[*big.Int]
func SuggestGasTipCap ¶ added in v1.19.0
func SuggestGasTipCap() CallBuilder[*big.Int]
func SyncProgress ¶ added in v1.19.0
func SyncProgress() CallBuilder[*ethereum.SyncProgress]
func TransactionCount ¶ added in v1.19.0
func TransactionCount(blockHash common.Hash) CallBuilder[uint]
func TransactionInBlock ¶ added in v1.19.0
func TransactionInBlock(blockHash common.Hash, index uint) CallBuilder[*types.Transaction]
func TransactionReceipt ¶ added in v1.19.0
func TransactionReceipt(txHash common.Hash) CallBuilder[*types.Receipt]
func TransactionSender ¶ added in v1.19.0
func TransactionSender(tx *types.Transaction, block common.Hash, index uint) CallBuilder[common.Address]
func (CallBuilder[T]) Into ¶ added in v1.19.0
func (b CallBuilder[T]) Into(ret *T) Call
type CallBuilder2 ¶ added in v1.19.0
type CallBuilder2[T1, T2 any] struct { // contains filtered or unexported fields }
func TransactionByHash ¶ added in v1.19.0
func TransactionByHash(hash common.Hash) CallBuilder2[*types.Transaction, bool]
func (CallBuilder2[T1, T2]) Into ¶ added in v1.19.0
func (b CallBuilder2[T1, T2]) Into(ret1 *T1, ret2 *T2) Call
type Interface ¶ added in v1.19.0
type Interface interface { // ChainID = eth_chainId ChainID(ctx context.Context) (*big.Int, error) // BlockByHash = eth_getBlockByHash (true) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) // BlockByNumber = eth_getBlockByNumber (true) BlockByNumber(ctx context.Context, blockNum *big.Int) (*types.Block, error) // BlockNumber = eth_blockNumber BlockNumber(ctx context.Context) (uint64, error) // BlockRange = eth_getBlockRange // https://community.optimism.io/docs/developers/build/json-rpc/#eth-getblockrange BlockRange(ctx context.Context, startBlockNum, endBlockNum *big.Int) ([]*types.Block, error) // PeerCount = net_peerCount PeerCount(ctx context.Context) (uint64, error) // HeaderByHash = eth_getBlockByHash (false) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) // HeaderByNumber = eth_getBlockByHash (true) HeaderByNumber(ctx context.Context, blockNum *big.Int) (*types.Header, error) // TransactionByHash = eth_getTransactionByHash TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, pending bool, err error) // TransactionSender is a wrapper for eth_getTransactionByBlockHashAndIndex TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error) // TransactionCount = eth_getBlockTransactionCountByHash TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) // TransactionInBlock = eth_getTransactionByBlockHashAndIndex TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) // TransactionReceipt = eth_getTransactionReceipt TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) // SyncProgress = eth_syncing SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) // NetworkID = net_version NetworkID(ctx context.Context) (*big.Int, error) // BalanceAt = eth_getBalance BalanceAt(ctx context.Context, account common.Address, blockNum *big.Int) (*big.Int, error) // StorageAt = eth_getStorageAt StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNum *big.Int) ([]byte, error) // CodeAt = eth_getCode CodeAt(ctx context.Context, account common.Address, blockNum *big.Int) ([]byte, error) // NonceAt = eth_getTransactionCount NonceAt(ctx context.Context, account common.Address, blockNum *big.Int) (uint64, error) // FilterLogs = eth_getLogs FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) // PendingBalanceAt = eth_getBalance ("pending") PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) // PendingStorageAt = eth_getStorageAt ("pending") PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) // PendingCodeAt = eth_getCode ("pending") PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) // PendingNonceAt = eth_getTransactionCount ("pending") PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) // PendingTransactionCount = eth_getBlockTransactionCountByNumber ("pending") PendingTransactionCount(ctx context.Context) (uint, error) // CallContract = eth_call (blockNumber) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNum *big.Int) ([]byte, error) // CallContractAtHash = eth_call (blockHash) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error) // PendingCallContract = eth_call ("pending") PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) // SuggestGasPrice = eth_gasPrice SuggestGasPrice(ctx context.Context) (*big.Int, error) // SuggestGasTipCap = eth_maxPriorityFeePerGas SuggestGasTipCap(ctx context.Context) (*big.Int, error) // FeeHistory = eth_feeHistory FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error) // EstimateGas = eth_estimateGas EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) // SendTransaction = eth_sendRawTransaction SendTransaction(ctx context.Context, tx *types.Transaction) error // SendRawTransaction = eth_sendRawTransaction SendRawTransaction(ctx context.Context, signedTxHex string) (common.Hash, error) }
type Option ¶ added in v1.19.0
type Option func(*Provider)
func WithBreaker ¶ added in v1.19.0
func WithHTTPClient ¶ added in v1.19.0
func WithHTTPClient(c httpClient) Option
func WithLogger ¶ added in v1.19.0
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
func (*Provider) BlockByHash ¶ added in v1.1.7
func (*Provider) BlockByNumber ¶
func (*Provider) BlockNumber ¶ added in v1.19.0
func (*Provider) BlockRange ¶ added in v1.19.0
func (*Provider) CallContract ¶ added in v1.19.0
func (*Provider) CallContractAtHash ¶ added in v1.19.0
func (*Provider) ContractQuery ¶ added in v1.19.0
func (p *Provider) ContractQuery(ctx context.Context, contractAddress string, inputAbiExpr, outputAbiExpr string, args interface{}) ([]string, error)
ie, ContractQuery(context.Background(), "0xabcdef..", "balanceOf(uint256)", "uint256", []string{"1"}) TODO: add common methods in helpers util, and also use generics to convert the return for us
func (*Provider) EstimateGas ¶ added in v1.19.0
func (*Provider) FeeHistory ¶ added in v1.19.0
func (*Provider) FilterLogs ¶ added in v1.19.0
func (*Provider) HeaderByHash ¶ added in v1.19.0
func (*Provider) HeaderByNumber ¶ added in v1.19.0
func (*Provider) PendingBalanceAt ¶ added in v1.19.0
func (*Provider) PendingCallContract ¶ added in v1.19.0
func (*Provider) PendingCodeAt ¶ added in v1.19.0
func (*Provider) PendingNonceAt ¶ added in v1.19.0
func (*Provider) PendingStorageAt ¶ added in v1.19.0
func (*Provider) PendingTransactionCount ¶ added in v1.19.0
func (*Provider) SendRawTransaction ¶ added in v1.3.6
func (*Provider) SendTransaction ¶ added in v1.19.0
func (*Provider) SetHTTPClient ¶ added in v1.19.0
func (*Provider) SubscribeFilterLogs ¶ added in v1.19.0
func (p *Provider) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
SubscribeFilterLogs is stubbed below so we can adhere to the bind.ContractBackend interface.
func (*Provider) SuggestGasPrice ¶ added in v1.19.0
func (*Provider) SuggestGasTipCap ¶ added in v1.19.0
func (*Provider) SyncProgress ¶ added in v1.19.0
func (*Provider) TransactionByHash ¶ added in v1.19.0
func (*Provider) TransactionCount ¶ added in v1.19.0
func (*Provider) TransactionInBlock ¶ added in v1.19.0
func (*Provider) TransactionReceipt ¶ added in v1.19.0
Source Files ¶
Click to show internal directories.
Click to hide internal directories.