txbuilder

package
v0.0.0-...-b770427 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FeeDelegationTxType is the transaction type for fee delegation (StableNet specific)
	FeeDelegationTxType = 0x16
)
View Source
const SimpleStorageBytecode = "" /* 407-byte string literal not displayed */

SimpleStorageBytecode is a simple storage contract bytecode for testing contract SimpleStorage { uint256 value; function set(uint256 v) { value = v; } function get() view returns (uint256) { return value; } }

Variables

View Source
var (
	// transfer(address,uint256) = 0xa9059cbb
	ERC20TransferSelector = common.FromHex("0xa9059cbb")
	// balanceOf(address) = 0x70a08231
	ERC20BalanceOfSelector = common.FromHex("0x70a08231")
	// approve(address,uint256) = 0x095ea7b3
	ERC20ApproveSelector = common.FromHex("0x095ea7b3")
)

ERC20 function selectors

Functions

func AddressFromKey

func AddressFromKey(key *ecdsa.PrivateKey) common.Address

AddressFromKey returns the address for a private key

func DistributeTransactions

func DistributeTransactions(numAccounts, totalTxs int) map[int]int

DistributeTransactions distributes transactions across multiple accounts Returns a map of account index to number of transactions for that account

func SignTransaction

func SignTransaction(tx *types.Transaction, chainID *big.Int, key *ecdsa.PrivateKey) (*types.Transaction, error)

SignTransaction signs a transaction with the given private key

Types

type BaseBuilder

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

BaseBuilder provides common functionality for all builders

func NewBaseBuilder

func NewBaseBuilder(config *BuilderConfig, estimator GasEstimator) *BaseBuilder

NewBaseBuilder creates a new base builder

func (*BaseBuilder) GetGasSettings

func (b *BaseBuilder) GetGasSettings(ctx context.Context) (gasTipCap, gasFeeCap *big.Int, err error)

GetGasSettings returns gas settings, fetching from network if not configured

type Builder

type Builder interface {
	// Build creates transactions for the given accounts
	Build(ctx context.Context, keys []*ecdsa.PrivateKey, nonces []uint64, count int) ([]*SignedTx, error)
	// EstimateGas estimates gas for a single transaction
	EstimateGas(ctx context.Context) (uint64, error)
	// Name returns the builder name
	Name() string
}

Builder interface defines the contract for transaction builders

type BuilderConfig

type BuilderConfig struct {
	ChainID   *big.Int
	GasLimit  uint64
	GasPrice  *big.Int
	GasTipCap *big.Int
	GasFeeCap *big.Int
	Value     *big.Int // Transfer value (default: 1 wei)
}

BuilderConfig holds configuration for transaction building

type BuilderOption

type BuilderOption func(*builderOptions)

BuilderOption is a functional option for builder configuration

func WithABI

func WithABI(abiJSON string) BuilderOption

WithABI sets the contract ABI

func WithAmount

func WithAmount(amount *big.Int) BuilderOption

WithAmount sets the transfer amount

func WithBytecode

func WithBytecode(bytecode []byte) BuilderOption

WithBytecode sets the contract bytecode

func WithContractAddress

func WithContractAddress(addr common.Address) BuilderOption

WithContractAddress sets the contract address

func WithFeePayerKey

func WithFeePayerKey(key *ecdsa.PrivateKey) BuilderOption

WithFeePayerKey sets the fee payer key for fee delegation

func WithMethod

func WithMethod(method string, args ...interface{}) BuilderOption

WithMethod sets the contract method

func WithNFTContract

func WithNFTContract(addr common.Address) BuilderOption

WithNFTContract sets the NFT contract address

func WithNFTName

func WithNFTName(name string) BuilderOption

WithNFTName sets the NFT collection name

func WithNFTSymbol

func WithNFTSymbol(symbol string) BuilderOption

WithNFTSymbol sets the NFT collection symbol

func WithRecipient

func WithRecipient(addr common.Address) BuilderOption

WithRecipient sets the recipient address

func WithTokenAddress

func WithTokenAddress(addr common.Address) BuilderOption

WithTokenAddress sets the token address for ERC20

func WithTokenURI

func WithTokenURI(uri string) BuilderOption

WithTokenURI sets the token URI for NFT minting

type ContractArtifact

type ContractArtifact struct {
	ContractName string          `json:"contractName"`
	ABI          json.RawMessage `json:"abi"`
	Bytecode     string          `json:"bytecode"`
}

ContractArtifact represents the compiled contract JSON structure

type ContractCallBuilder

type ContractCallBuilder struct {
	*BaseBuilder
	// contains filtered or unexported fields
}

ContractCallBuilder builds contract call transactions

func NewContractCallBuilder

func NewContractCallBuilder(config *BuilderConfig, estimator GasEstimator, contractAddr common.Address) *ContractCallBuilder

NewContractCallBuilder creates a new contract call builder

func (*ContractCallBuilder) Build

func (b *ContractCallBuilder) Build(ctx context.Context, keys []*ecdsa.PrivateKey, nonces []uint64, count int) ([]*SignedTx, error)

Build creates contract call transactions

func (*ContractCallBuilder) EstimateGas

func (b *ContractCallBuilder) EstimateGas(_ context.Context) (uint64, error)

EstimateGas estimates gas for contract call

func (*ContractCallBuilder) Name

func (b *ContractCallBuilder) Name() string

Name returns the builder name

func (*ContractCallBuilder) WithABI

func (b *ContractCallBuilder) WithABI(abiJSON string) (*ContractCallBuilder, error)

WithABI sets the contract ABI

func (*ContractCallBuilder) WithMethod

func (b *ContractCallBuilder) WithMethod(methodSig string, args ...interface{}) *ContractCallBuilder

WithMethod sets the method to call

type ContractCallRequest

type ContractCallRequest struct {
	TxRequest
	Method string
	Args   []interface{}
}

ContractCallRequest represents a contract call request

type ContractDeployBuilder

type ContractDeployBuilder struct {
	*BaseBuilder
	// contains filtered or unexported fields
}

ContractDeployBuilder builds contract deployment transactions

func NewContractDeployBuilder

func NewContractDeployBuilder(config *BuilderConfig, estimator GasEstimator) *ContractDeployBuilder

NewContractDeployBuilder creates a new contract deploy builder

func (*ContractDeployBuilder) Build

func (b *ContractDeployBuilder) Build(ctx context.Context, keys []*ecdsa.PrivateKey, nonces []uint64, count int) ([]*SignedTx, error)

Build creates contract deployment transactions

func (*ContractDeployBuilder) EstimateGas

func (b *ContractDeployBuilder) EstimateGas(_ context.Context) (uint64, error)

EstimateGas estimates gas for contract deployment

func (*ContractDeployBuilder) Name

func (b *ContractDeployBuilder) Name() string

Name returns the builder name

func (*ContractDeployBuilder) WithBytecode

func (b *ContractDeployBuilder) WithBytecode(bytecode []byte) *ContractDeployBuilder

WithBytecode sets custom contract bytecode

type ERC20TransferBuilder

type ERC20TransferBuilder struct {
	*BaseBuilder
	// contains filtered or unexported fields
}

ERC20TransferBuilder builds ERC20 transfer transactions

func NewERC20TransferBuilder

func NewERC20TransferBuilder(config *BuilderConfig, estimator GasEstimator, tokenAddr common.Address) *ERC20TransferBuilder

NewERC20TransferBuilder creates a new ERC20 transfer builder

func (*ERC20TransferBuilder) Build

func (b *ERC20TransferBuilder) Build(ctx context.Context, keys []*ecdsa.PrivateKey, nonces []uint64, count int) ([]*SignedTx, error)

Build creates ERC20 transfer transactions

func (*ERC20TransferBuilder) EstimateGas

func (b *ERC20TransferBuilder) EstimateGas(_ context.Context) (uint64, error)

EstimateGas estimates gas for ERC20 transfer

func (*ERC20TransferBuilder) Name

func (b *ERC20TransferBuilder) Name() string

Name returns the builder name

func (*ERC20TransferBuilder) WithAmount

func (b *ERC20TransferBuilder) WithAmount(amount *big.Int) *ERC20TransferBuilder

WithAmount sets the transfer amount

func (*ERC20TransferBuilder) WithRecipient

func (b *ERC20TransferBuilder) WithRecipient(addr common.Address) *ERC20TransferBuilder

WithRecipient sets the recipient address

type ERC20TransferRequest

type ERC20TransferRequest struct {
	TxRequest
	TokenAddress common.Address
	Recipient    common.Address
	Amount       *big.Int
}

ERC20TransferRequest represents an ERC20 transfer request

type ERC721MintBuilder

type ERC721MintBuilder struct {
	*BaseBuilder
	// contains filtered or unexported fields
}

ERC721MintBuilder builds ERC721 NFT minting transactions

func NewERC721MintBuilder

func NewERC721MintBuilder(config *BuilderConfig, estimator GasEstimator) (*ERC721MintBuilder, error)

NewERC721MintBuilder creates a new ERC721 mint builder

func (*ERC721MintBuilder) Build

func (b *ERC721MintBuilder) Build(ctx context.Context, keys []*ecdsa.PrivateKey, nonces []uint64, count int) ([]*SignedTx, error)

Build creates ERC721 mint transactions (createNFT calls)

func (*ERC721MintBuilder) DeployContract

func (b *ERC721MintBuilder) DeployContract(ctx context.Context, key *ecdsa.PrivateKey, nonce uint64) (common.Address, common.Hash, error)

DeployContract deploys the NFT contract and returns the contract address

func (*ERC721MintBuilder) EstimateGas

func (b *ERC721MintBuilder) EstimateGas(_ context.Context) (uint64, error)

EstimateGas estimates gas for NFT minting

func (*ERC721MintBuilder) GetContractAddress

func (b *ERC721MintBuilder) GetContractAddress() common.Address

GetContractAddress returns the NFT contract address

func (*ERC721MintBuilder) GetDeployTransaction

func (b *ERC721MintBuilder) GetDeployTransaction(ctx context.Context, key *ecdsa.PrivateKey, nonce uint64) (*SignedTx, error)

GetDeployTransaction returns the signed deployment transaction

func (*ERC721MintBuilder) Name

func (b *ERC721MintBuilder) Name() string

Name returns the builder name

func (*ERC721MintBuilder) WithContract

func (b *ERC721MintBuilder) WithContract(addr common.Address) *ERC721MintBuilder

WithContract sets the NFT contract address

func (*ERC721MintBuilder) WithNFTName

func (b *ERC721MintBuilder) WithNFTName(name string) *ERC721MintBuilder

WithNFTName sets the NFT collection name (for deployment)

func (*ERC721MintBuilder) WithNFTSymbol

func (b *ERC721MintBuilder) WithNFTSymbol(symbol string) *ERC721MintBuilder

WithNFTSymbol sets the NFT collection symbol (for deployment)

func (*ERC721MintBuilder) WithTokenURI

func (b *ERC721MintBuilder) WithTokenURI(uri string) *ERC721MintBuilder

WithTokenURI sets the base token URI for minting

type Factory

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

Factory creates builders based on configuration

func NewFactory

func NewFactory(cfg *BuilderConfig, estimator GasEstimator) *Factory

NewFactory creates a new builder factory

func (*Factory) CreateBuilder

func (f *Factory) CreateBuilder(mode config.Mode, opts ...BuilderOption) (Builder, error)

CreateBuilder creates a builder based on the mode

type FeeDelegationBuilder

type FeeDelegationBuilder struct {
	*BaseBuilder
	// contains filtered or unexported fields
}

FeeDelegationBuilder builds fee delegation transactions (Type 0x16) This is a StableNet-specific transaction type where a fee payer pays gas on behalf of the sender

func NewFeeDelegationBuilder

func NewFeeDelegationBuilder(config *BuilderConfig, estimator GasEstimator, feePayerKey *ecdsa.PrivateKey) *FeeDelegationBuilder

NewFeeDelegationBuilder creates a new fee delegation builder

func (*FeeDelegationBuilder) Build

func (b *FeeDelegationBuilder) Build(ctx context.Context, keys []*ecdsa.PrivateKey, nonces []uint64, count int) ([]*SignedTx, error)

Build creates fee delegation transactions for the given accounts

func (*FeeDelegationBuilder) EstimateGas

func (b *FeeDelegationBuilder) EstimateGas(_ context.Context) (uint64, error)

EstimateGas estimates gas for a fee delegation transfer

func (*FeeDelegationBuilder) Name

func (b *FeeDelegationBuilder) Name() string

Name returns the builder name

func (*FeeDelegationBuilder) WithRecipient

func (b *FeeDelegationBuilder) WithRecipient(addr common.Address) *FeeDelegationBuilder

WithRecipient sets the recipient address

type FeeDelegationRequest

type FeeDelegationRequest struct {
	TxRequest
	FeePayer    common.Address
	FeePayerKey *ecdsa.PrivateKey
}

FeeDelegationRequest extends TxRequest for fee delegation

type FeeDelegationTx

type FeeDelegationTx struct {
	// Sender transaction (EIP-1559 style)
	ChainID    *big.Int
	Nonce      uint64
	GasTipCap  *big.Int
	GasFeeCap  *big.Int
	Gas        uint64
	To         *common.Address
	Value      *big.Int
	Data       []byte
	AccessList types.AccessList

	// Sender signature
	V *big.Int
	R *big.Int
	S *big.Int

	// Fee payer
	FeePayer *common.Address

	// Fee payer signature
	FV *big.Int
	FR *big.Int
	FS *big.Int
}

FeeDelegationTx represents a fee delegation transaction (Type 0x16) This is StableNet-specific transaction type

type GasEstimator

type GasEstimator interface {
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
}

GasEstimator interface for gas estimation

type SignedTx

type SignedTx struct {
	Tx       *types.Transaction
	RawTx    []byte
	Hash     common.Hash
	From     common.Address
	Nonce    uint64
	GasLimit uint64
}

SignedTx represents a signed transaction ready to send

type TransferBuilder

type TransferBuilder struct {
	*BaseBuilder
	// contains filtered or unexported fields
}

TransferBuilder builds simple native coin transfer transactions (EIP-1559)

func NewTransferBuilder

func NewTransferBuilder(config *BuilderConfig, estimator GasEstimator) *TransferBuilder

NewTransferBuilder creates a new transfer builder

func (*TransferBuilder) Build

func (b *TransferBuilder) Build(ctx context.Context, keys []*ecdsa.PrivateKey, nonces []uint64, count int) ([]*SignedTx, error)

Build creates transfer transactions for the given accounts

func (*TransferBuilder) BuildSingle

func (b *TransferBuilder) BuildSingle(
	ctx context.Context,
	key *ecdsa.PrivateKey,
	nonce uint64,
	to common.Address,
	value *big.Int,
) (*SignedTx, error)

BuildSingle creates a single transfer transaction

func (*TransferBuilder) EstimateGas

func (b *TransferBuilder) EstimateGas(_ context.Context) (uint64, error)

EstimateGas estimates gas for a simple transfer

func (*TransferBuilder) Name

func (b *TransferBuilder) Name() string

Name returns the builder name

func (*TransferBuilder) WithRecipient

func (b *TransferBuilder) WithRecipient(addr common.Address) *TransferBuilder

WithRecipient sets the recipient address

type TxRequest

type TxRequest struct {
	From      common.Address
	To        *common.Address
	Value     *big.Int
	Data      []byte
	Nonce     uint64
	Gas       uint64
	GasPrice  *big.Int // for legacy tx
	GasTipCap *big.Int // for EIP-1559
	GasFeeCap *big.Int // for EIP-1559
	ChainID   *big.Int
}

TxRequest represents a transaction request

type TxType

type TxType byte

TxType represents the transaction type

const (
	// Standard Ethereum transaction types
	TxTypeLegacy     TxType = 0x00
	TxTypeAccessList TxType = 0x01
	TxTypeDynamicFee TxType = 0x02
	TxTypeBlob       TxType = 0x03

	// StableNet specific transaction types
	TxTypeFeeDelegation TxType = 0x16
)

Jump to

Keyboard shortcuts

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