Documentation ¶
Overview ¶
Package ethereum higher level Go API's for writing applications and smart contracts on the Ethereum blockchain.
Index ¶
- Constants
- func FromAddressAny(value any, signature string) (string, error)
- func FromAddressBytes(bytes []byte, signature string) (string, error)
- func PrivateKeyByKeyFile(keyFile string, passPhrase string) (*ecdsa.PrivateKey, error)
- func SignAny(value any, privateKey *ecdsa.PrivateKey) (signature string, err error)
- func SignBytes(bytes []byte, privateKey *ecdsa.PrivateKey) (signature string, err error)
- type Backend
- type Client
- func (clt *Client) Address() common.Address
- func (clt *Client) Balance(ctx context.Context) (wei *big.Int, err error)
- func (clt *Client) BaseFee(receipt *types.Receipt) (wei *big.Int)
- func (clt *Client) ChainID() int
- func (clt *Client) Network() string
- func (clt *Client) NewCallOpts(ctx context.Context) (*bind.CallOpts, error)
- func (clt *Client) NewTransactOpts(ctx context.Context, gasLimit uint64, gasPrice *big.Int, valueGWei *big.Float) (*bind.TransactOpts, error)
- func (clt *Client) PrivateKey() *ecdsa.PrivateKey
- func (clt *Client) SendTransaction(ctx context.Context, address common.Address, value *big.Int, gasLimit uint64) error
- func (clt *Client) WaitMined(ctx context.Context, tx *types.Transaction) (*types.Receipt, error)
- type DialedBackend
- type SimulatedBackend
Constants ¶
const ( NetworkHTTPLocalhost = "http://localhost:8545" NetworkLocalhost = "zarf/ethereum/geth.ipc" NetworkGoerli = "https://rpc.ankr.com/eth_goerli" )
Set of networks supported by the smart package.
const ZeroHash string = "0x0000000000000000000000000000000000000000000000000000000000000000"
ZeroHash represents a hash code of zeros.
Variables ¶
This section is empty.
Functions ¶
func FromAddressAny ¶ added in v0.5.0
FromAddressAny marshals the specified value into JSON to create an array of bytes. Then uses FromAddressBytes function to extract the address.
func FromAddressBytes ¶ added in v0.5.0
FromAddressBytes extracts the address for the account that signed the data. The signature must be provided as a hexadecimal string.
func PrivateKeyByKeyFile ¶
func PrivateKeyByKeyFile(keyFile string, passPhrase string) (*ecdsa.PrivateKey, error)
PrivateKeyByKeyFile opens a key file for the private key.
func SignAny ¶ added in v0.5.0
func SignAny(value any, privateKey *ecdsa.PrivateKey) (signature string, err error)
SignAny marshals the specified value into JSON to create an array of bytes. Then the SignBytes function is used to sign the data.
func SignBytes ¶ added in v0.5.0
func SignBytes(bytes []byte, privateKey *ecdsa.PrivateKey) (signature string, err error)
SignBytes takes the specified bytes and first hashes them using Keccak256 to create a 32 byte array of data. Then those bytes are salted with the Ethereum stamp and signed using the specified private key. The signature is returned as a hexadecimal string.
Types ¶
type Backend ¶ added in v0.8.0
type Backend interface { bind.ContractBackend bind.DeployBackend TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) BalanceAt(ctx context.Context, contract common.Address, blockNumber *big.Int) (*big.Int, error) Network() string ChainID() *big.Int }
Backend represents behavior for interacting with an ethereum node.
type Client ¶ added in v0.8.0
type Client struct { Backend // contains filtered or unexported fields }
Client provides an API for working with smart contracts.
func NewClient ¶ added in v0.8.0
func NewClient(backend Backend, privateKey *ecdsa.PrivateKey) (*Client, error)
NewClient provides an API for accessing an Ethereum node to perform blockchain related operations. It required the private key you want to use for this instance when accessing the node.
func (*Client) Address ¶ added in v0.8.0
Address returns the current address calculated from the private key.
func (*Client) Balance ¶ added in v0.8.0
Balance retrieves the current balance for the client account.
func (*Client) BaseFee ¶ added in v0.8.0
BaseFee calculates the base fee from the block for this receipt.
func (*Client) ChainID ¶ added in v0.8.0
ChainID returns the chain information for the connected network.
func (*Client) Network ¶ added in v0.11.0
Network returns the network information for the connected network.
func (*Client) NewCallOpts ¶ added in v0.8.0
NewCallOpts constructs a new CallOpts which is used to call contract methods that does not require a transaction.
func (*Client) NewTransactOpts ¶ added in v0.8.0
func (clt *Client) NewTransactOpts(ctx context.Context, gasLimit uint64, gasPrice *big.Int, valueGWei *big.Float) (*bind.TransactOpts, error)
NewTransactOpts constructs a new TransactOpts which is the collection of authorization data required to create a valid Ethereum transaction. If the gasLimit is set to 0, an estimate will be made for the amount of gas needed. If the gasPrice is set to 0, then the connected geth service is consulted for the suggested gas price.
func (*Client) PrivateKey ¶ added in v0.8.0
func (clt *Client) PrivateKey() *ecdsa.PrivateKey
PrivateKey returns the private key being used.
func (*Client) SendTransaction ¶ added in v0.8.0
func (clt *Client) SendTransaction(ctx context.Context, address common.Address, value *big.Int, gasLimit uint64) error
SendTransaction sends a transaction to the specified address for the specified amount. The function will wait for the transaction to be mined based on the timeout value specified in the context.
type DialedBackend ¶ added in v0.8.0
DialedBackend represents a dialied connection to an ethereum node.
func CreateDialedBackend ¶ added in v0.8.0
func CreateDialedBackend(ctx context.Context, network string) (*DialedBackend, error)
CreateDialedBackend constructs an ethereum client value for the specified network and attempts to establish a connection.
func (*DialedBackend) ChainID ¶ added in v0.8.0
func (b *DialedBackend) ChainID() *big.Int
ChainID returns the chain id the backend is connected to.
func (*DialedBackend) Network ¶ added in v0.8.0
func (b *DialedBackend) Network() string
Network returns the network the backend is connected to.
type SimulatedBackend ¶ added in v0.8.0
type SimulatedBackend struct { simulated.Client *simulated.Backend AutoCommit bool PrivateKeys []*ecdsa.PrivateKey // contains filtered or unexported fields }
SimulatedBackend represents a simulated connection to an ethereum node.
func CreateSimulatedBackend ¶ added in v0.8.0
func CreateSimulatedBackend(numAccounts int, autoCommit bool, accountBalance *big.Int) (*SimulatedBackend, error)
CreateSimulatedBackend constructs a simulated backend and a set of private keys registered to the backend with a balance of 100 ETH. Use these private keys with the NewSimulation call to get an Ethereum API value.
func (*SimulatedBackend) ChainID ¶ added in v0.8.0
func (b *SimulatedBackend) ChainID() *big.Int
ChainID returns the chain id the backend is connected to.
func (*SimulatedBackend) Network ¶ added in v0.11.0
func (b *SimulatedBackend) Network() string
Network returns the network the backend is connected to.
func (*SimulatedBackend) SendTransaction ¶ added in v0.8.0
func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error
SendTransaction functions pipes its parameters to the embedded backend and also calls Commit() if sb.AutoCommit==true.
func (*SimulatedBackend) SetTime ¶ added in v0.9.0
func (b *SimulatedBackend) SetTime(t time.Time)
SetTime creates a time shift to the simulated clock. It can only be called on empty blocks.