ethclient

package
v0.0.0-...-4fc266b Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_CONFIRMATIONS = 12
)

Variables

View Source
var (
	ErrHashesOnlyBlockHash          = errors.New("only transactions hashes requested")
	ErrTransactionNotFound          = errors.New("transaction not found")
	ErrInvalidAddressCheckSum       = errors.New("invalid address checksum")
	ErrInvalidAddress               = errors.New("invalid address")
	ErrTransactionNotTransfer       = errors.New("transaction not transfer")
	ErrUnsupportedTransactionFormat = errors.New("unsupported transaction format")
	ErrUnsupportedTransactionType   = errors.New("unsupported transaction type")
	ErrTransactionSignError         = errors.New("transaction sign error")
	ErrInsufficientFunds            = errors.New("insufficient funds")
	ErrNothingToTransfer            = errors.New("nothing to transfer")
	ErrConfigStorageEmpty           = errors.New("config storage is empty")
	ErrUnknownToken                 = errors.New("unknown token")
)

Functions

func GetAddressCodec

func GetAddressCodec() address.AddressCodec

func WeiToEtherFloat

func WeiToEtherFloat(wei *big.Int) *big.Float

func WeiToEtherString

func WeiToEtherString(wei *big.Int) string

Types

type AddressCodec

type AddressCodec struct {
}

func (*AddressCodec) DecodeAddressToBytes

func (a *AddressCodec) DecodeAddressToBytes(addressStr string) ([]byte, error)

func (*AddressCodec) EncodeBytesToAddress

func (a *AddressCodec) EncodeBytesToAddress(addressBytes []byte) (string, error)

func (*AddressCodec) IsValid

func (a *AddressCodec) IsValid(address string) bool

func (*AddressCodec) PrivateKeyToAddress

func (a *AddressCodec) PrivateKeyToAddress(privateKey []byte) (address string, addressBytes []byte, err error)

type Block

type Block struct {
	// FullTransactions set to true if "returns the full transaction"
	// parameter set
	FullTransactions bool `json:"hashesOnly"`

	// Number The block number. null when its pending block.
	Number int64 `json:"number"`

	// Hash 32 Bytes - hash of the block. null when its pending block.
	Hash string `json:"hash"`

	// ParentHash 32 Bytes - hash of the parent block.
	ParentHash string `json:"parentHash"`

	// ParentBeaconBlockRoot 32 Bytes - hash of the parent beacon block.
	ParentBeaconBlockRoot string `json:"parentBeaconBlockRoot"`

	// Nonce 8 Bytes - hash of the generated proof-of-work. null when its pending block.
	Nonce uint64 `json:"nonce"`

	// Sha3Uncles 32 Bytes - SHA3 of the uncles data in the block.
	Sha3Uncles string `json:"sha3Uncles"`

	// LogsBloom 256 Bytes - the bloom filter for the logs of the block.
	// null when its pending block.
	LogsBloom string `json:"logsBloom"`

	// TransactionsRoot 32 Bytes - the root of the transaction
	// trie of the block.
	TransactionsRoot string `json:"transactionsRoot"`

	// StateRoot 32 Bytes - the root of the final state trie of the block.
	StateRoot string `json:"stateRoot"`

	// ReceiptsRoot 32 Bytes - the root of the receipts trie of the block.
	ReceiptsRoot string `json:"receiptsRoot"`

	// Miner DATA, 20 Bytes - the address of the beneficiary to whom the mining
	Miner string `json:"miner"`

	// BaseFeePerGas A string of the base fee encoded in hexadecimal format.
	// Please note that this response field will not be included in a block
	// requested before the EIP-1559 upgrade
	BaseFeePerGas *big.Int `json:"baseFeePerGas"`

	// Difficulty The integer of the difficulty for this block
	// encoded as a hexadecimal
	Difficulty int64 `json:"difficulty"`

	// TotalDifficulty integer of the difficulty for this block
	// encoded as a hexadecimal
	TotalDifficulty string `json:"totalDifficulty"`

	// ExtraData The "extra data" field of this block
	ExtraData string `json:"extraData"`

	// Size integer the size of this block in bytes.
	Size int64 `json:"size"`

	// GasLimit the maximum gas allowed in this block
	GasLimit int64 `json:"gasLimit"`

	// GasUsed the total used gas by all transactions in this block.
	GasUsed int64 `json:"gasUsed"`

	// Timestamp the unix timestamp for when the block was collated.
	Timestamp int64 `json:"timestamp"`

	// BlobGasUsed
	BlobGasUsed   string `json:"blobGasUsed"`
	ExcessBlobGas string `json:"excessBlobGas"`

	MixHash string `json:"mixHash"`

	// Transactions Array of transaction objects, or 32 Bytes
	// transaction hashes depending on the last given parameter.
	Transactions json.RawMessage `json:"transactions"`

	// Uncles Array of uncle hashes.
	Uncles []string `json:"uncles"`

	Withdrawals     json.RawMessage `json:"withdrawals"`
	WithdrawalsRoot string          `json:"withdrawalsRoot"`
	// contains filtered or unexported fields
}

func (*Block) GetTransactions

func (b *Block) GetTransactions() (txs []*Transaction, err error)

GetTransactions returns the transactions from the block. If the block was requested without full transactions, it will return error

func (*Block) GetTransactionsHashes

func (b *Block) GetTransactionsHashes() (txs []string)

GetTransactionsHashes returns the transaction hashes from the block.

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON Since Ethereum uses non-standard encoding of integer data (0x prefixed hex) in its RPC responses, we need to implement full decoding of transactions and blocks through a special method.

func (*Block) WalkTransactions

func (b *Block) WalkTransactions(view func(tx *Transaction) (stop bool)) error

WalkTransactions walks through the transactions of the block and calls the view function for each transaction. If the view function returns true, the walking is stopped. If the block was requested without full transactions, it will return error

func (*Block) WalkTransactionsHashes

func (b *Block) WalkTransactionsHashes(view func(tx string) (stop bool))

WalkTransactionsHashes walks through the transaction hashes of the block and calls the view function for each transaction. If the view function returns true, the walking is stopped.

type Client

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

func NewClient

func NewClient(options ...Option) *Client

func (*Client) BalanceOf

func (c *Client) BalanceOf(address string) (balance *big.Int, err error)

func (*Client) BlockByHash

func (c *Client) BlockByHash(blockHash string, fullInfo bool) (block *types.BlockInfo, err error)

func (*Client) BlockByNum

func (c *Client) BlockByNum(blockNum int64, fullInfo bool) (block *types.BlockInfo, err error)

func (*Client) BlockNum

func (c *Client) BlockNum() (blockNum int64, err error)

func (*Client) Call

func (c *Client) Call(contractAddress, data string) (callResult string, err error)

Call executes a new message call immediately without creating a transaction on the block chain. By default "latest" is used for the block tag. If you need call with specific block number, use CallByBlockNumber. Often used for executing read-only smart contract functions, for example the balanceOf for an ERC-20 contract.

func (*Client) CallByBlockNumber

func (c *Client) CallByBlockNumber(contractAddress, data string, blockNumber int64) (callResult string, err error)

CallByBlockNumber executes a new message call immediately without creating a transaction on the block chain. Often used for executing read-only smart contract functions, for example the balanceOf for an ERC-20 contract.

func (*Client) ContractGetBalanceOf

func (c *Client) ContractGetBalanceOf(contractAddress, address string) (balance *big.Int, err error)

func (*Client) Decimals

func (c *Client) Decimals() (decimals int)

func (*Client) GasPrice

func (c *Client) GasPrice() (*big.Int, error)

GasPrice returns the current price per gas in wei. The gas price is determined by the last few blocks median gas price. You need know the gas price for calculate the fee of transaction send/execute.

func (*Client) GetAddressCodec

func (c *Client) GetAddressCodec() address.AddressCodec

func (*Client) GetBalance

func (c *Client) GetBalance(address string) (*big.Int, error)

GetBalance returns the balance of the account of given address. The balance is returned in wei. if you want to convert it to ether, use WeiToEther function.

func (*Client) GetBlockByHash

func (c *Client) GetBlockByHash(hash string, fullTransactions bool) (*Block, error)

GetBlockByHash returns information about a block by hash. If "fullTransactions" is true it returns the full transaction objects, if "fullTransactions" is false, only the hashes of the transactions.

func (*Client) GetBlockByNumber

func (c *Client) GetBlockByNumber(number int64, fullTransactions bool) (*Block, error)

GetBlockByNumber returns information about a block by block number. If "fullTransactions" is true it returns the full transaction objects, if "fullTransactions" is false, only the hashes of the transactions.

func (*Client) GetBlockNumber

func (c *Client) GetBlockNumber() (int64, error)

GetBlockNumber returns the number of most recent block.

func (*Client) GetChainId

func (c *Client) GetChainId() (chainId string)

func (*Client) GetChainName

func (c *Client) GetChainName() (chainName string)

func (*Client) GetChainSymbol

func (c *Client) GetChainSymbol() (chainSymbol string)

func (*Client) GetEstimatedFee

func (c *Client) GetEstimatedFee(from, to, data string, amount *big.Int) (fee, gasPrice *big.Int, gas int64, err error)

func (*Client) GetEstimatedGas

func (c *Client) GetEstimatedGas(from, to, data string, amount *big.Int) (gas int64, err error)

func (*Client) GetEstimatedGasPrice

func (c *Client) GetEstimatedGasPrice() (gasPrice *big.Int, err error)

func (*Client) GetNetId

func (c *Client) GetNetId() (netId int64, err error)

func (*Client) GetTransactionByBlockHashAndIndex

func (c *Client) GetTransactionByBlockHashAndIndex(hash string, index int) (*Transaction, error)

GetTransactionByBlockHashAndIndex returns the information about a transaction requested by block hash and tx index. If the transaction not found (geth rpc call return null), it returns error.

func (*Client) GetTransactionByBlockNumberAndIndex

func (c *Client) GetTransactionByBlockNumberAndIndex(blockNumber int64, index int) (*Transaction, error)

GetTransactionByBlockNumberAndIndex returns the information about a transaction requested by block number and tx index. If the transaction not found (geth rpc call return null), it returns error.

func (*Client) GetTransactionByHash

func (c *Client) GetTransactionByHash(hash string) (*Transaction, error)

GetTransactionByHash returns the information about a transaction requested by transaction hash. If the transaction not found (geth rpc call return null), it returns error.

func (*Client) GetTxPoolContent

func (c *Client) GetTxPoolContent() (pending, queued map[string]map[string]*Transaction, err error)

GetTxPoolContent returns the information about the transaction pool. It returns two maps: pending and queued transactions.

func (*Client) Init

func (c *Client) Init() error

func (*Client) MemPoolContent

func (c *Client) MemPoolContent() (poolContent []*types.TransferInfo, err error)

func (*Client) MinConfirmations

func (c *Client) MinConfirmations() (confirmations int)

func (*Client) PendingNonceAt

func (c *Client) PendingNonceAt(address string) (nonce int64, err error)

func (*Client) SendRawTransaction

func (c *Client) SendRawTransaction(data string) (txHash string, err error)

SendRawTransaction sends the signed and RPL encoded transaction to the network. In fact, any transaction - transfer of funds, call of a smart contract function or deployment of a smart contract is carried out by calling this function

func (*Client) SetConfirmations

func (c *Client) SetConfirmations(confirmations int)

func (*Client) TokenProtocols

func (c *Client) TokenProtocols() []string

func (*Client) TokensBalanceOf

func (c *Client) TokensBalanceOf(address string, token string) (balance *big.Int, err error)

func (*Client) TokensList

func (c *Client) TokensList() (tokensList []*types.TokenInfo)

func (*Client) TransactionSendRaw

func (c *Client) TransactionSendRaw(rawTx []byte) (txHash string, err error)

func (*Client) TransferAllByPrivateKey

func (c *Client) TransferAllByPrivateKey(fromPrivateKey []byte, from, to string) (txHash string, err error)

func (*Client) TransferAllTokenByPrivateKey

func (c *Client) TransferAllTokenByPrivateKey(fromPrivateKey []byte, from, to string, token string) (txHash string, err error)

func (*Client) TransferByPrivateKey

func (c *Client) TransferByPrivateKey(fromPrivateKey []byte, from, to string, amount *big.Int) (txHash string, err error)

func (*Client) TransferGetEstimatedFee

func (c *Client) TransferGetEstimatedFee(from, to string, amount *big.Int) (fee *big.Int, err error)

func (*Client) TransferInfoByHash

func (c *Client) TransferInfoByHash(txHash string) (tx *types.TransferInfo, err error)

func (*Client) TransferInfoByNum

func (c *Client) TransferInfoByNum(blockNum int64, txIndex int) (tx *types.TransferInfo, err error)

func (*Client) TransferTokenByPrivateKey

func (c *Client) TransferTokenByPrivateKey(fromPrivateKey []byte, from, to string, amount *big.Int, token string) (txHash string, err error)

func (*Client) TransferTokenGetEstimatedFee

func (c *Client) TransferTokenGetEstimatedFee(from, to string, amount *big.Int, token string) (fee *big.Int, err error)

type Config

type Config struct {
	ChainName     string
	ChainId       string
	ChainSymbol   string
	Decimals      int
	Confirmations int  `json:"confirmations"`
	Debug         bool `json:"debug"`
	Tokens        []*types.TokenInfo
	// contains filtered or unexported fields
}

func (*Config) Load

func (c *Config) Load() (err error)

func (*Config) Save

func (c *Config) Save() (err error)

type EthAddress

type EthAddress string

func (EthAddress) IsValidate

func (a EthAddress) IsValidate() bool

type Option

type Option func(*Client)

func WithAbiManager

func WithAbiManager(abiManager *abi.SmartContractsManager) Option

func WithConfigStorage

func WithConfigStorage(storage storage.BinStorage) Option

func WithIPCClient

func WithIPCClient(ipcPath string) Option

func WithRpcClient

func WithRpcClient(nodeAddress, nodePort string, useSSL bool, headers map[string]string) Option

type Transaction

type Transaction struct {
	BlockHash        string          `json:"blockHash"`
	BlockNumber      int64           `json:"blockNumber"`
	Hash             string          `json:"hash"`
	From             string          `json:"from"`
	To               string          `json:"to"`
	Gas              int64           `json:"gas"`
	GasPrice         *big.Int        `json:"gasPrice"`
	Value            *big.Int        `json:"value"`
	Input            string          `json:"input"`
	Nonce            int64           `json:"nonce"`
	TransactionIndex int64           `json:"transactionIndex"`
	Type             int64           `json:"type"`
	ChainId          int64           `json:"chainId"`
	AccessList       json.RawMessage `json:"accessList"`
	V                string          `json:"v"`
	R                string          `json:"r"`
	S                string          `json:"s"`
}

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON Since Ethereum uses non-standard encoding of integer data (0x prefixed hex) in its RPC responses, we need to implement full decoding of transactions and blocks through a special method.

Jump to

Keyboard shortcuts

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