evm

package
v1.16.39 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package evm provides EVM chain interaction and transaction utilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownErrorSelector = fmt.Errorf("unknown error selector")

Functions

func CalculateEvmFeeInLux

func CalculateEvmFeeInLux(gasUsed uint64, gasPrice *big.Int) float64

func ConvertToNanoLux

func ConvertToNanoLux(balance *big.Int) *big.Int

ConvertToNanoLux converts a balance in Lux to NanoLux. It adds 0.5 to the balance before dividing by 1e9 to round it to the nearest whole number.

func ExtractWarpMessageFromLogs

func ExtractWarpMessageFromLogs(
	logs []*types.Log,
) (*warp.UnsignedMessage, error)

ExtractWarpMessageFromLogs gets first unsigned warp message contained in [logs].

func ExtractWarpMessageFromReceipt

func ExtractWarpMessageFromReceipt(
	receipt *types.Receipt,
) (*warp.UnsignedMessage, error)

ExtractWarpMessageFromReceipt gets first unsigned warp message contained in [receipt].

func GetClientWithoutScheme

func GetClientWithoutScheme(rpcURL string) (ethclient.Client, string, error)

GetClientWithoutScheme tries to connect an ethclient to a rpc url without scheme, by trying out different possible schemes: ws, wss, https, http

func GetErrorFromTrace

func GetErrorFromTrace(
	trace map[string]interface{},
	functionSignatureToError map[string]error,
) (error, error)

GetErrorFromTrace returns golang error associated with [trace] by using [functionSignatureToError] to map function signatures to evm function selectors in [trace], and then to golang errors. First returned error is the mapped error, second error is for errors obtained executing this function.

func GetEventFromLogs

func GetEventFromLogs[T any](logs []*types.Log, parser func(log types.Log) (T, error)) (T, error)

GetEventFromLogs returns the first log in 'logs' that is successfully parsed by 'parser'.

func GetFunctionSelector

func GetFunctionSelector(functionSignature string) string

GetFunctionSelector returns evm function selector code for the given function signature. EVM maps function and error signatures into codes that are then used in traces.

func GetTxTrace

func GetTxTrace(rpcURL string, txID string) (map[string]interface{}, error)

GetTxTrace returns a trace for the given [txID] on [rpcURL]. Supports [repeatsOnFailure] failures.

func GetWarpMessagesFromLogs

func GetWarpMessagesFromLogs(
	logs []*types.Log,
) []*warp.UnsignedMessage

GetWarpMessagesFromLogs gets all unsigned warp messages contained in [logs].

func HasScheme

func HasScheme(rpcURL string) (bool, error)

func HexToAddress

func HexToAddress(s string) common.Address

HexToAddress converts hex string to common.Address (geth type)

func PrivateKeyToAddress

func PrivateKeyToAddress(privateKey string) (crypto.Address, error)

PrivateKeyToAddress returns the public address associated with [privateKey].

func TransactionError

func TransactionError(tx *types.Transaction, err error, msg string, args ...interface{}) error

TransactionError transforms a tx operation error into an error that contains: - the [err] itself - the [tx] hash (or information on the tx not being submitted) - another descriptive [msg], together with formatted [args]

func TxDump

func TxDump(description string, tx *types.Transaction) (string, error)

TxDump dumps a [tx] hexa description, for it to be separately issued using external tools.

Types

type Client

type Client struct {
	EthClient ethclient.Client
	URL       string
}

Client wraps over ethclient for calls used by SDK. Features: - finds out url scheme in case it is missing, to connect to ws/wss/http/https - repeats to try to recover from failures, generating its own context for each call - logs rpc url in case of failure - receives addresses and private keys as strings

func GetClient

func GetClient(rpcURL string) (Client, error)

GetClient connects an evm client to the given [rpcURL] supports [repeatsOnFailure] failures

func (Client) BlockByNumber

func (client Client) BlockByNumber(n *big.Int) (*types.Block, error)

BlockByNumber gets block [n] supports [repeatsOnFailure] failures

func (Client) BlockNumber

func (client Client) BlockNumber() (uint64, error)

BlockNumber gets current height supports [repeatsOnFailure] failures

func (Client) CalculateTxParams

func (client Client) CalculateTxParams(
	address string,
) (*big.Int, *big.Int, uint64, error)

CalculateTxParams returns gasFeeCap, gasTipCap, and nonce to be used when constructing a transaction supports [repeatsOnFailure] failures on each step

func (Client) ChainConfig

func (client Client) ChainConfig() (*evmParams.ChainConfigWithUpgradesJSON, error)

ChainConfig returns the chain conf supports [repeatsOnFailure] failures

func (Client) Close

func (client Client) Close()

Close closes underlying ethclient connection

func (Client) ContractAlreadyDeployed

func (client Client) ContractAlreadyDeployed(
	contractAddress string,
) (bool, error)

ContractAlreadyDeployed indicates wether a contract is deployed on [contractAddress] supports [repeatsOnFailure] failures

func (Client) CreateDummyBlocks

func (client Client) CreateDummyBlocks(
	numBlocks int,
	privKeyStr string,
) error

CreateDummyBlocks issues dummy txs to create the given number of blocks

func (Client) EstimateBaseFee

func (client Client) EstimateBaseFee() (*big.Int, error)

EstimateBaseFee returns the estimated base fee supports [repeatsOnFailure] failures

func (Client) EstimateGasLimit

func (client Client) EstimateGasLimit(
	msg ethereum.CallMsg,
) (uint64, error)

EstimateGasLimit returns the estimated gas limit supports [repeatsOnFailure] failures

func (Client) FilterLogs

func (client Client) FilterLogs(query ethereum.FilterQuery) ([]types.Log, error)

FilterLogs gets logs as given by [query] supports [repeatsOnFailure] failures

func (Client) FundAddress

func (client Client) FundAddress(
	sourceAddressPrivateKeyStr string,
	targetAddressStr string,
	amount *big.Int,
) (*types.Receipt, error)

FundAddress transfers [amount] to [targetAddressStr] using [sourceAddressPrivateKeyStr] supports [repeatsOnFailure] failures on each step

func (Client) GetAddressBalance

func (client Client) GetAddressBalance(
	addressStr string,
) (*big.Int, error)

GetAddressBalance returns the balance for [address] supports [repeatsOnFailure] failures

func (Client) GetChainID

func (client Client) GetChainID() (*big.Int, error)

GetChainID returns the chain ID supports [repeatsOnFailure] failures

func (Client) GetContractBytecode

func (client Client) GetContractBytecode(
	contractAddressStr string,
) ([]byte, error)

GetContractBytecode returns the contract bytecode at [contractAddress] supports [repeatsOnFailure] failures

func (Client) GetPrivateKeyBalance

func (client Client) GetPrivateKeyBalance(
	privateKey string,
) (*big.Int, error)

GetPrivateKeyBalance returns the balance for [privateKey] supports [repeatsOnFailure] failures

func (Client) GetTxOptsWithSigner

func (client Client) GetTxOptsWithSigner(
	prefundedPrivateKeyStr string,
) (*bind.TransactOpts, error)

GetTxOptsWithSigner returns tx options that include signer for [prefundedPrivateKeyStr] supports [repeatsOnFailure] failures when gathering chain info

func (Client) IssueTx

func (client Client) IssueTx(
	txStr string,
) error

IssueTx encodes [txStr] to binary, sends and waits for it supports [repeatsOnFailure] failures on each step

func (Client) NonceAt

func (client Client) NonceAt(
	addressStr string,
) (uint64, error)

NonceAt returns the nonce at [address] supports [repeatsOnFailure] failures

func (Client) SendTransaction

func (client Client) SendTransaction(
	tx *types.Transaction,
) error

SendTransaction sends [tx] supports [repeatsOnFailure] failures

func (Client) SetupProposerVM

func (client Client) SetupProposerVM(
	privKey string,
) error

SetupProposerVM issues transactions on [client] so as to activate Proposer VM Fork this should generate a PostForkBlock because its parent block (genesis) has a timestamp (0) that is greater than or equal to the fork activation time of 0. Therefore, subsequent blocks should be built with BuildBlockWithContext. the current timestamp should be after the ProposerVM activation time (aka ApricotPhase4). supports [repeatsOnFailure] failures on each step

func (Client) SuggestGasTipCap

func (client Client) SuggestGasTipCap() (*big.Int, error)

SuggestGasTipCap returns the suggested gas tip supports [repeatsOnFailure] failures

func (Client) TransactWithWarpMessage

func (client Client) TransactWithWarpMessage(
	from crypto.Address,
	privateKeyStr string,
	warpMessage *warp.Message,
	contract crypto.Address,
	callData []byte,
	value *big.Int,
	generateRawTxOnly bool,
) (*types.Transaction, error)

TransactWithWarpMessage generates a transaction signed with [privateKeyStr], calling a [contract] method using [callData] including [warpMessage] in the tx accesslist if [generateRawTxOnly] is set, it generates a similar, unsigned tx, with given [from] address

func (Client) TransactionReceipt

func (client Client) TransactionReceipt(hash common.Hash) (*types.Receipt, error)

TransactionReceipt gets tx receipt for hash supports [repeatsOnFailure] failures

func (Client) WaitForEVMBootstrapped

func (client Client) WaitForEVMBootstrapped(timeout time.Duration) error

WaitForEVMBootstrapped waits for [timeout] until evm is bootstrapped considers evm is bootstrapped if it responds to an evm call (ChainID)

func (Client) WaitForNewBlock

func (client Client) WaitForNewBlock(
	prevBlockNumber uint64,
	totalDuration time.Duration,
) error

WaitForNewBlock waits until current height is bigger than the given previous height at [prevBlockNumber] supports [repeatsOnFailure] failures on each step

func (Client) WaitForTransaction

func (client Client) WaitForTransaction(
	tx *types.Transaction,
) (*types.Receipt, bool, error)

WaitForTransaction waits for [tx]'s receipt to have successful state supports [repeatsOnFailure] failures

type RawClient

type RawClient struct {
	RPCClient *rpc.Client
	URL       string
	// also used at mocks
	CallContext func(context.Context, interface{}, string, ...interface{}) error
}

RawClient wraps over rpc.Client for calls used by SDK. Used to make evm calls not available in ethclient: - debug trace call - debug trace transaction Features: - finds out url scheme in case it is missing, to connect to ws/wss/http/https - repeats to try to recover from failures, generating its own context for each call - logs rpc url in case of failure

func GetRawClient

func GetRawClient(rpcURL string) (RawClient, error)

GetRawClient connects a raw evm rpc client to the given [rpcURL]. Supports [repeatsOnFailure] failures.

func (RawClient) Close

func (client RawClient) Close()

Close closes underlying rpc connection.

func (RawClient) DebugTraceCall

func (client RawClient) DebugTraceCall(
	data map[string]string,
) (map[string]interface{}, error)

DebugTraceCall returns a trace for making a call on [client] with the given [data]. Supports [repeatsOnFailure] failures.

func (RawClient) DebugTraceTransaction

func (client RawClient) DebugTraceTransaction(
	txID string,
) (map[string]interface{}, error)

DebugTraceTransaction returns a trace for the given [txID] on [client]. Supports [repeatsOnFailure] failures.

Jump to

Keyboard shortcuts

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