wallet

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SwarmTokenDecimals = 16
	LocalnetChainID    = 12345
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendClient

type BackendClient interface {
	ChainID(ctx context.Context) (*big.Int, error)
	CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
	EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error)
	BalanceAt(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error)
}

type Key

type Key string

func GenerateKey

func GenerateKey() (Key, error)

func (Key) PrivateECDSA

func (k Key) PrivateECDSA() (*ecdsa.PrivateKey, error)

func (Key) PublicAddress

func (k Key) PublicAddress() (common.Address, error)

func (Key) PublicECDSA

func (k Key) PublicECDSA() (*ecdsa.PublicKey, error)

type Option added in v0.4.0

type Option func(*options)

Option configures a Wallet.

func WithLookup added in v0.4.0

func WithLookup(timeout, interval time.Duration) Option

WithLookup sets how long, and how often, the chain is asked for a transaction whose send failed before the send is reported as failed. The defaults are 15s and 1s. A timeout at or below zero uses the default, an interval at or below zero asks once. Some nodes reject a transaction they did keep, e.g. Nethermind answers "replacement transaction underpriced" for one already in its pool.

func WithRetry added in v0.4.0

func WithRetry(retries int, delay time.Duration) Option

WithRetry sets how many times a failed send is retried, waiting delay between attempts. The default is 0, which sends once; negative values count as 0. Every attempt re-sends the same signed transaction, so at most one can be mined. A transaction the node rejected is not retried.

type Token

type Token struct {
	Contract common.Address
	Symbol   string
	Decimals int
}

func NativeCoinForChain

func NativeCoinForChain(cid int64) (Token, error)

func SwarmTokenForChain

func SwarmTokenForChain(cid int64) (Token, error)

type TokenInfoGetterFn

type TokenInfoGetterFn = func(cid int64) (Token, error)

type TokenWallet

type TokenWallet interface {
	Balance(
		ctx context.Context,
		addr common.Address,
		token Token,
	) (*big.Int, error)

	Transfer(
		ctx context.Context,
		toAddr common.Address,
		amount *big.Int,
		token Token,
	) error
}

type TransactionSender

type TransactionSender interface {
	Send(
		ctx context.Context,
		toAddr common.Address,
		amount *big.Int,
		callData []byte,
	) error
}

type Wallet

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

func New

func New(client BackendClient, key Key, opts ...Option) *Wallet

func (*Wallet) BalanceERC20

func (w *Wallet) BalanceERC20(
	ctx context.Context,
	addr common.Address,
	token Token,
) (*big.Int, error)

func (*Wallet) BalanceNative

func (w *Wallet) BalanceNative(
	ctx context.Context,
	addr common.Address,
) (*big.Int, error)

func (*Wallet) ChainID

func (w *Wallet) ChainID(ctx context.Context) (int64, error)

func (*Wallet) ERC20

func (w *Wallet) ERC20() TokenWallet

func (*Wallet) Native

func (w *Wallet) Native() TokenWallet

func (*Wallet) PublicAddress

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

func (*Wallet) TransferERC20

func (w *Wallet) TransferERC20(
	ctx context.Context,
	toAddr common.Address,
	amount *big.Int,
	token Token,
) error

func (*Wallet) TransferNative

func (w *Wallet) TransferNative(
	ctx context.Context,
	toAddr common.Address,
	amount *big.Int,
) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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