wallet

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package wallet provides Ethereum wallet management for transaction signing.

Index

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) Address

func (w *Wallet) Address() common.Address

Address returns the wallet's Ethereum address.

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

func (w *Wallet) GetBalance(ctx context.Context) (*big.Int, error)

GetBalance fetches the current balance from the chain.

func (*Wallet) GetNonce

func (w *Wallet) GetNonce(ctx context.Context) (uint64, error)

GetNonce fetches the current nonce from the chain.

func (*Wallet) GetRPCClient

func (w *Wallet) GetRPCClient() *execution.Client

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

func (w *Wallet) SendTransaction(ctx context.Context, tx *types.Transaction) error

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.

func (*Wallet) Sync

func (w *Wallet) Sync(ctx context.Context) error

Sync synchronizes the wallet state with the chain.

Jump to

Keyboard shortcuts

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