contract

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package contract provides generic smart contract interaction for EVM chains.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default context timeout for contract calls.

View Source
const MaxRetries = 3

MaxRetries is the default number of retry attempts for transaction submission.

Variables

View Source
var (
	ErrTxReverted     = errors.New("transaction reverted")
	ErrReceiptTimeout = errors.New("receipt timeout")
)

Sentinel errors for contract call operations.

Functions

func ParseABI

func ParseABI(abiJSON string) (*abi.ABI, error)

ParseABI parses a JSON ABI string into a go-ethereum ABI object.

Types

type ABICache

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

ABICache is a thread-safe cache for parsed contract ABIs.

func NewABICache

func NewABICache() *ABICache

NewABICache creates a new ABI cache.

func (*ABICache) Get

func (c *ABICache) Get(chainID int64, address common.Address) (*abi.ABI, bool)

Get retrieves a cached ABI for the given chain and address.

func (*ABICache) GetOrParse

func (c *ABICache) GetOrParse(chainID int64, address common.Address, abiJSON string) (*abi.ABI, error)

GetOrParse retrieves a cached ABI or parses the JSON and caches the result.

func (*ABICache) Set

func (c *ABICache) Set(chainID int64, address common.Address, parsed *abi.ABI)

Set stores a parsed ABI in the cache.

type Caller

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

Caller provides read and write access to smart contracts.

func NewCaller

func NewCaller(rpc *ethclient.Client, wp wallet.WalletProvider, chainID int64, cache *ABICache) *Caller

NewCaller creates a contract caller.

func (*Caller) LoadABI

func (c *Caller) LoadABI(chainID int64, address common.Address, abiJSON string) error

LoadABI parses and caches an ABI for later use.

func (*Caller) Read

Read calls a view/pure function on a contract (no tx, no gas).

func (*Caller) Write

Write sends a state-changing transaction to a contract.

type ContractCallRequest

type ContractCallRequest struct {
	ChainID int64          `json:"chainId"`
	Address common.Address `json:"address"`
	ABI     string         `json:"abi"` // JSON ABI string
	Method  string         `json:"method"`
	Args    []interface{}  `json:"args"`
	Value   *big.Int       `json:"value,omitempty"` // ETH value for payable functions
}

ContractCallRequest holds parameters for a contract call.

type ContractCallResult

type ContractCallResult struct {
	Data    []interface{} `json:"data"`
	TxHash  string        `json:"txHash,omitempty"`
	GasUsed uint64        `json:"gasUsed,omitempty"`
}

ContractCallResult holds the result of a contract call.

type ContractCaller

type ContractCaller interface {
	Read(ctx context.Context, req ContractCallRequest) (*ContractCallResult, error)
	Write(ctx context.Context, req ContractCallRequest) (*ContractCallResult, error)
}

ContractCaller abstracts read and write access to smart contracts.

Jump to

Keyboard shortcuts

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