Documentation
¶
Overview ¶
Package wallet provides Ethereum wallet management for transaction signing.
Index ¶
- type Wallet
- func (w *Wallet) Address() common.Address
- func (w *Wallet) Await(ctx context.Context, txHash common.Hash, timeout time.Duration) (*types.Receipt, error)
- func (w *Wallet) BuildAndSend(ctx context.Context, to common.Address, value *big.Int, data []byte, ...) (*types.Transaction, error)
- func (w *Wallet) BuildTransaction(ctx context.Context, to common.Address, value *big.Int, data []byte, ...) (*types.Transaction, error)
- func (w *Wallet) GetBalance(ctx context.Context) (*big.Int, error)
- func (w *Wallet) GetNonce(ctx context.Context) (uint64, error)
- func (w *Wallet) GetRPCClient() *execution.Client
- func (w *Wallet) SendAndConfirm(ctx context.Context, to common.Address, value *big.Int, data []byte, ...) (*types.Receipt, error)
- func (w *Wallet) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (w *Wallet) SignTransaction(tx *types.Transaction) (*types.Transaction, error)
- func (w *Wallet) Sync(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
Wallet manages an Ethereum wallet for transaction operations.
The wallet is safe to use when multiple independent buildoor instances share the same funding key: each transaction sources a fresh on-chain nonce, txMu serializes this process's own submissions, and SendAndConfirm resolves cross-process nonce conflicts (refetch + retry) and detects its tx being displaced by another instance.
func NewWallet ¶
func NewWallet( privkeyHex string, rpcClient *execution.Client, log logrus.FieldLogger, ) (*Wallet, error)
NewWallet creates a new wallet from a hex-encoded private key.
func (*Wallet) Await ¶
func (w *Wallet) Await( ctx context.Context, txHash common.Hash, timeout time.Duration, ) (*types.Receipt, error)
Await waits for a transaction to be confirmed.
func (*Wallet) BuildAndSend ¶
func (w *Wallet) BuildAndSend( ctx context.Context, to common.Address, value *big.Int, data []byte, gasLimit uint64, ) (*types.Transaction, error)
BuildAndSend builds, signs, and sends a transaction.
func (*Wallet) BuildTransaction ¶
func (w *Wallet) BuildTransaction( ctx context.Context, to common.Address, value *big.Int, data []byte, gasLimit uint64, ) (*types.Transaction, error)
BuildTransaction creates a new unsigned transaction.
func (*Wallet) GetBalance ¶
GetBalance fetches the current balance from the chain.
func (*Wallet) GetRPCClient ¶
GetRPCClient returns the underlying concrete RPC client.
func (*Wallet) SendAndConfirm ¶
func (w *Wallet) SendAndConfirm( ctx context.Context, to common.Address, value *big.Int, data []byte, gasLimit uint64, timeout time.Duration, ) (*types.Receipt, error)
SendAndConfirm builds, signs, sends, and confirms a transaction in a way that is safe when several buildoor instances share this funding key.
Each attempt sources a fresh on-chain nonce. Crucially, it never parses the send error string (which varies per execution client). Instead it decides what to do by observing node state: whether our specific transaction is known to the node, and where the account's pending nonce sits relative to the nonce we used.
- our tx is known (pending/mined) -> wait for its receipt
- our tx is unknown and the pending nonce has moved past ours -> another tx (likely another instance) took our slot; resubmit with a fresh nonce
- our tx is unknown, the nonce is still free, and the send errored -> genuine failure; surface it
txMu serializes this process's own submissions so concurrent lifecycle operations (e.g. the startup deposit and a balance top-up) never collide with each other.
func (*Wallet) SendTransaction ¶
SendTransaction sends a signed transaction.
func (*Wallet) SignTransaction ¶
func (w *Wallet) SignTransaction(tx *types.Transaction) (*types.Transaction, error)
SignTransaction signs a transaction with the wallet's private key.