goeth_tx_helper

package module
v0.0.0-...-1d9192b Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 14 Imported by: 0

README

goeth-tx-helper

Simplifies performing transaction in Ethereum network and parsing logs. Based on go-ethereum project.

Methods:

  • CreateEIP1559TxHelper()
  • GetGasParameters()
  • GetBaseFee()
  • SendTransaction()
  • FilterTransactionLog()
  • ContractFunctionCall()
  • ContractFunctionCallNoArguments()
  • GetLatestBlockNumber()
  • GetEthClient()
  • GetRpcUrl()
  • GetPublicAddressFromPrivateKey()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPublicAddressFromPrivateKey

func GetPublicAddressFromPrivateKey(privateKey *ecdsa.PrivateKey) (common.Address, error)

func WrapExternalError

func WrapExternalError(originalErr error, message string) error

WrapExternalError to easily create a new error which wraps the given error.

Types

type EIP1559TransactionHelper

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

func CreateEIP1559TxHelper

func CreateEIP1559TxHelper(rpcUrl string, gasTip int64, emulation bool, receiptMock types.Receipt) *EIP1559TransactionHelper

CreateEIP1559TxHelper

gasTip is optional parameter, if 0 passed, default gasTip = 2_000_000_000 is applied.
However, 2_000_000_000 is too much for L2 networks, it's much bigger than L2 base fee,
and when calculating total transaction cost = gasAmountNeeded * maxFeePerGas,
where maxFeePerGas = 2 * baseFee + GasTipCap (https://www.blocknative.com/blog/eip-1559-fees),
total gas needed (gasAmountNeeded) can be too high and unacceptable for low banks (greater than transaction net value),
and lead to error "insufficient funds for gas * price + value"
For L2 networks gasTip = 100_000_000 is recommended

func (*EIP1559TransactionHelper) ContractFunctionCall

func (eipHelper *EIP1559TransactionHelper) ContractFunctionCall(contractAddress *common.Address, contractABI abi.ABI, blockNumber *big.Int, methodName string, args ...interface{}) ([]interface{}, error)

ContractFunctionCall calls method "methodName" in contract "contractAddress"

[READONLY] This is NOT-state-changing call

func (*EIP1559TransactionHelper) ContractFunctionCallNoArguments

func (eipHelper *EIP1559TransactionHelper) ContractFunctionCallNoArguments(contractAddress *common.Address, contractABI abi.ABI, blockNumber *big.Int, methodName string) ([]interface{}, error)

ContractFunctionCallNoArguments calls method "methodName" in contract "contractAddress", suitable for methods with NO arguments

[READONLY] This is NOT-state-changing call

func (*EIP1559TransactionHelper) FilterTransactionLog

func (eipHelper *EIP1559TransactionHelper) FilterTransactionLog(txReceipt *types.Receipt, txLogs []*types.Log, filter ethereum.FilterQuery) ([]types.Log, error)

FilterTransactionLog filters INDEXED (only topics) transaction logs by applying ethereum.FilterQuery filter

How filter works:

BlockHash |
FromBlock |
ToBlock   |- are all ignored, because we expect either txReceipt OR txLogs from one specific transaction, we should not (and don't want to) iterate through blocks!

Addresses - restricts matches to events created by specific contracts, if EMPTY -> ANY address will pass, also see -> ethereum.FilterQuery

Topics - restricts matches to particular event topics, an empty element slice matches any topic, also see -> ethereum.FilterQuery

func (*EIP1559TransactionHelper) GetBaseFee

func (eipHelper *EIP1559TransactionHelper) GetBaseFee() (*big.Int, error)

func (*EIP1559TransactionHelper) GetEthClient

func (eipHelper *EIP1559TransactionHelper) GetEthClient() *ethclient.Client

func (*EIP1559TransactionHelper) GetGasParameters

func (eipHelper *EIP1559TransactionHelper) GetGasParameters(from common.Address, to *common.Address, value *big.Int, data []byte) (Gas1559Params, error)

func (*EIP1559TransactionHelper) GetLatestBlockNumber

func (eipHelper *EIP1559TransactionHelper) GetLatestBlockNumber() (*big.Int, error)

func (*EIP1559TransactionHelper) GetPublicAddressFromPrivateKey

func (eipHelper *EIP1559TransactionHelper) GetPublicAddressFromPrivateKey(privateKey *ecdsa.PrivateKey) (common.Address, error)

func (*EIP1559TransactionHelper) GetRpcUrl

func (eipHelper *EIP1559TransactionHelper) GetRpcUrl() string

func (*EIP1559TransactionHelper) SendTransaction

func (eipHelper *EIP1559TransactionHelper) SendTransaction(
	privateKey *ecdsa.PrivateKey,
	to *common.Address,
	chainID *big.Int,
	gasParams Gas1559Params,
	value *big.Int,
	data []byte,
) (receipt *types.Receipt, err error)

type ExternalErrorWrapper

type ExternalErrorWrapper struct {
	OriginalError     error
	OurMessage        string
	AdditionalContext string
}

func (*ExternalErrorWrapper) AddContext

func (e *ExternalErrorWrapper) AddContext(additionalInfo string)

func (*ExternalErrorWrapper) Error

func (e *ExternalErrorWrapper) Error() string

Error is mark the struct as an error.

func (*ExternalErrorWrapper) Unwrap

func (e *ExternalErrorWrapper) Unwrap() error

Unwrap is used to make it work with errors.Is, errors.As.

type Gas1559Params

type Gas1559Params struct {
	GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas
	GasFeeCap *big.Int // a.k.a. maxFeePerGas
	Gas       uint64
}

type TxHelperRegistry

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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