Documentation
¶
Index ¶
- Constants
- Variables
- func Base(b int64) *big.Int
- func CallConstantFunction(ctx context.Context, client Client, myabi ABI, address string, ...) ([]interface{}, error)
- func CompileSolidityString(ctx context.Context, source, solcVersion, evmVersion string, optimize bool) (map[string]*Contract, error)
- func ConvertArgument(abiType ABIType, param interface{}) (interface{}, error)
- func ConvertArguments(args ABIArguments, params []interface{}) ([]interface{}, error)
- func ConvertInt(signed bool, size int, i *big.Int) (interface{}, error)
- func DecToInt(d decimal.Decimal, decimals int32) *big.Int
- func DecodeBig(s string) (*big.Int, error)
- func DecodeHex(s string) ([]byte, error)
- func DecodeRevert(data []byte, myabi *ABI) (string, bool)
- func DecodeUint64(s string) (uint64, error)
- func EncodeBig(bigint *big.Int) string
- func EncodeHex(b []byte) string
- func EncodeRawTransaction(tx *Transaction) ([]byte, error)
- func EncodeUint64(i uint64) string
- func EncryptKeystore(acc *Account, auth string, scryptN, scryptP int) ([]byte, error)
- func FloatAsInt(amountF *big.Float, decimals int) *big.Int
- func FormatRPCError(err error, myabi *ABI) error
- func FromECDSA(priv *ecdsa.PrivateKey) []byte
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func FromHex(s string) []byte
- func GenerateGoBinding(pkgName, typeName, abiJSON, binHex string) ([]byte, error)
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func Gwei(g int64) *big.Int
- func HexToECDSA(hexKey string) (*ecdsa.PrivateKey, error)
- func IntAsFloat(i *big.Int, decimals int) *big.Float
- func IntToDec(i *big.Int, decimals int32) decimal.Decimal
- func IsHexAddress(s string) bool
- func Keccak256(data ...[]byte) []byte
- func NetworkNames() []string
- func ParseAmount(amount string) (*big.Int, error)
- func ParseBase(b string) (*big.Int, error)
- func ParseBigInt(value string) (*big.Int, error)
- func ParseCombinedJSON(combinedJSON []byte, ...) (map[string]*Contract, error)
- func ParseGwei(g string) (*big.Int, error)
- func PersonalSign(message []byte, prv *ecdsa.PrivateKey) ([]byte, error)
- func RLPEncode(val interface{}) ([]byte, error)
- func RecoverPubkey(digestHash, sig []byte) (*ecdsa.PublicKey, error)
- func SendTransaction(ctx context.Context, client Client, signedTx *Transaction) error
- func SignHash(digestHash []byte, prv *ecdsa.PrivateKey) ([]byte, error)
- func SignTransaction(tx *Transaction, chainID *big.Int, prv *ecdsa.PrivateKey) ([]byte, error)
- func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
- func WeiAsBase(w *big.Int) string
- func WeiAsGwei(w *big.Int) string
- type ABI
- type ABIArgument
- type ABIArguments
- type ABIError
- type ABIEvent
- type ABIMethod
- type ABIType
- type AccessTuple
- type Account
- type Address
- func BytesToAddress(b []byte) Address
- func CreateAddress(caller Address, nonce uint64) Address
- func HexToAddress(s string) Address
- func PersonalRecover(message, sig []byte) (Address, error)
- func PubkeyToAddress(p ecdsa.PublicKey) Address
- func RecoverAddress(digestHash, sig []byte) (Address, error)
- func RecoverTransactionSender(tx *Transaction) (Address, error)
- func (a Address) Bytes() []byte
- func (a Address) Hex() string
- func (a Address) IsZero() bool
- func (a Address) MarshalJSON() ([]byte, error)
- func (a Address) MarshalText() ([]byte, error)
- func (a Address) String() string
- func (a *Address) UnmarshalJSON(input []byte) error
- func (a *Address) UnmarshalText(input []byte) error
- type BatchElem
- type Block
- type BlockNonce
- type Bloom
- type CallMsg
- type Client
- type Contract
- type ContractInfo
- type Event
- type FilterQuery
- type Hash
- type HexBig
- type HexBytes
- type HexUint64
- type ID
- type Log
- type Network
- type RLPItem
- type RPCClient
- type RPCError
- type Receipt
- type Snapshot
- type Solidity
- type Tally
- type Transaction
- func CallFunctionWithArgs(ctx context.Context, client Client, privateKeyHex, address string, ...) (*Transaction, error)
- func CallFunctionWithData(ctx context.Context, client Client, privateKeyHex, address string, ...) (*Transaction, error)
- func CallFunctionWithDataOpts(ctx context.Context, client Client, privateKeyHex, address string, ...) (*Transaction, error)
- func CallFunctionWithOpts(ctx context.Context, client Client, privateKeyHex, address string, ...) (*Transaction, error)
- func CallTransactFunction(ctx context.Context, client Client, myabi ABI, ...) (*Transaction, error)
- func DeployBin(ctx context.Context, client Client, ...) (*Transaction, error)
- func DeployContract(ctx context.Context, client Client, privateKeyHex, binHex, abiJSON string, ...) (*Transaction, error)
- func DeployContractWithOpts(ctx context.Context, client Client, privateKeyHex, binHex, abiJSON string, ...) (*Transaction, error)
- func DeployEIP1967Proxy(ctx context.Context, client Client, privateKeyHex string, ...) (*Transaction, error)
- func Send(ctx context.Context, client Client, privateKeyHex string, to Address, ...) (*Transaction, error)
- func SendWithOpts(ctx context.Context, client Client, privateKeyHex string, to Address, ...) (*Transaction, error)
- type TxOptions
- type Vote
Constants ¶
const ( IntTy byte = iota UintTy BoolTy StringTy SliceTy ArrayTy TupleTy AddressTy FixedBytesTy BytesTy HashTy )
ABI Type kinds (kept compatible with classic Kind constants).
const ( AddressLength = 20 HashLength = 32 BloomLength = 256 )
const ( TxTypeLegacy uint8 = 0x00 TxTypeAccessList uint8 = 0x01 TxTypeDynamicFee uint8 = 0x02 ReceiptStatusFailed uint64 = 0 ReceiptStatusSuccessful uint64 = 1 )
const DefaultUserAgent = "gochain-web3/1.0"
Variables ¶
var ( ZeroAddress Address ZeroHash Hash )
var ( EmptyRootHash = HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") EmptyUncleHash = HexToHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347") )
var Networks = map[string]Network{ "gochain": { Name: "gochain", URL: mainnetURL, ChainID: big.NewInt(60), Unit: "GO", ExplorerURL: mainnetExplorerURL, }, "testnet": { Name: "testnet", URL: testnetURL, ChainID: big.NewInt(31337), Unit: "GO", ExplorerURL: testnetExplorerURL, }, "localhost": { Name: "localhost", URL: "http://localhost:8545", Unit: "ETH", }, "ethereum": { Name: "ethereum", URL: "https://ethereum-rpc.publicnode.com", ChainID: big.NewInt(1), Unit: "ETH", ExplorerURL: "https://etherscan.io", }, "sepolia": { Name: "sepolia", URL: "https://ethereum-sepolia-rpc.publicnode.com", ChainID: big.NewInt(11155111), Unit: "ETH", ExplorerURL: "https://sepolia.etherscan.io", }, "holesky": { Name: "holesky", URL: "https://ethereum-holesky-rpc.publicnode.com", ChainID: big.NewInt(17000), Unit: "ETH", ExplorerURL: "https://holesky.etherscan.io", }, "base": { Name: "base", URL: "https://mainnet.base.org", ChainID: big.NewInt(8453), Unit: "ETH", ExplorerURL: "https://basescan.org", }, "base-sepolia": { Name: "base-sepolia", URL: "https://sepolia.base.org", ChainID: big.NewInt(84532), Unit: "ETH", ExplorerURL: "https://sepolia.basescan.org", }, "arbitrum": { Name: "arbitrum", URL: "https://arb1.arbitrum.io/rpc", ChainID: big.NewInt(42161), Unit: "ETH", ExplorerURL: "https://arbiscan.io", }, "optimism": { Name: "optimism", URL: "https://mainnet.optimism.io", ChainID: big.NewInt(10), Unit: "ETH", ExplorerURL: "https://optimistic.etherscan.io", }, "polygon": { Name: "polygon", URL: "https://polygon-rpc.com", ChainID: big.NewInt(137), Unit: "POL", ExplorerURL: "https://polygonscan.com", }, "bsc": { Name: "bsc", URL: "https://bsc-dataseed.binance.org", ChainID: big.NewInt(56), Unit: "BNB", ExplorerURL: "https://bscscan.com", }, "avalanche": { Name: "avalanche", URL: "https://api.avax.network/ext/bc/C/rpc", ChainID: big.NewInt(43114), Unit: "AVAX", ExplorerURL: "https://snowtrace.io", }, }
var NotFoundErr = errors.New("not found")
Functions ¶
func CallConstantFunction ¶
func CallConstantFunction(ctx context.Context, client Client, myabi ABI, address string, functionName string, params ...interface{}) ([]interface{}, error)
CallConstantFunction executes a read-only contract call (eth_call) and unpacks the outputs.
func CompileSolidityString ¶
func CompileSolidityString(ctx context.Context, source, solcVersion, evmVersion string, optimize bool) (map[string]*Contract, error)
CompileSolidityString compiles Solidity source using a local solc binary if compatible or Docker ethereum/solc.
func ConvertArgument ¶
ConvertArgument converts param to the Go representation expected by abiType.
func ConvertArguments ¶
func ConvertArguments(args ABIArguments, params []interface{}) ([]interface{}, error)
ConvertArguments converts CLI strings, JSON numbers/arrays/objects, or Go values to ABI-ready Go types.
func ConvertInt ¶
ConvertInt converts i into the exact Go integer type corresponding to signedness and ABI bit size, validating both overflow AND underflow bounds.
func DecodeHex ¶ added in v1.0.0
DecodeHex decodes a 0x-prefixed (or unprefixed) even-length hex string.
func DecodeRevert ¶ added in v1.0.0
DecodeRevert decodes EVM revert return data into a human-readable message, handling standard Error(string), Panic(uint256), and custom ABI errors when myabi is provided.
func DecodeUint64 ¶ added in v1.0.0
DecodeUint64 parses a 0x-prefixed quantity hex string into uint64.
func EncodeRawTransaction ¶ added in v1.0.0
func EncodeRawTransaction(tx *Transaction) ([]byte, error)
EncodeRawTransaction encodes a signed Transaction into raw wire bytes.
func EncodeUint64 ¶ added in v1.0.0
EncodeUint64 encodes i as a 0x-prefixed quantity hex string (0x0 for zero).
func EncryptKeystore ¶ added in v1.0.0
EncryptKeystore encrypts an Account into Web3 Secret Storage V3 JSON (scrypt N=4096, r=8, p=6 for fast CLI usage or standard N).
func FloatAsInt ¶
FloatAsInt scales *big.Float amountF by 10^decimals into *big.Int.
func FormatRPCError ¶ added in v1.0.0
FormatRPCError enriches an RPCError with decoded Solidity revert details if revert data is present.
func FromECDSA ¶ added in v1.0.0
func FromECDSA(priv *ecdsa.PrivateKey) []byte
FromECDSA exports a private key as a 32-byte big-endian slice.
func FromECDSAPub ¶ added in v1.0.0
FromECDSAPub serializes a secp256k1 public key in 65-byte uncompressed format (0x04 || X || Y).
func FromHex ¶ added in v1.0.0
FromHex decodes hex string s (ignoring errors, returning empty slice on invalid hex).
func GenerateGoBinding ¶ added in v1.0.0
GenerateGoBinding generates a gofmt-formatted Go contract wrapper using package web3.
func GenerateKey ¶ added in v1.0.0
func GenerateKey() (*ecdsa.PrivateKey, error)
GenerateKey generates a new secp256k1 ECDSA private key.
func HexToECDSA ¶ added in v1.0.0
func HexToECDSA(hexKey string) (*ecdsa.PrivateKey, error)
HexToECDSA parses a 32-byte hex-encoded secp256k1 private key (with or without 0x prefix).
func IntAsFloat ¶
IntAsFloat converts a *big.Int (wei) to *big.Float given decimals.
func IsHexAddress ¶ added in v1.0.0
IsHexAddress reports whether s is a valid 40-hex-character EVM address (with optional 0x prefix).
func Keccak256 ¶ added in v1.0.0
Keccak256 computes the Ethereum Keccak-256 hash of the concatenated input slices.
func NetworkNames ¶ added in v1.0.0
func NetworkNames() []string
NetworkNames returns sorted built-in network names.
func ParseAmount ¶
ParseAmount parses a human-readable amount with optional unit suffix (wei, attogo, gwei, nanogo, eth, go) into wei.
func ParseBigInt ¶
ParseBigInt parses a base-10 integer string into *big.Int.
func ParseCombinedJSON ¶
func PersonalSign ¶ added in v1.0.0
func PersonalSign(message []byte, prv *ecdsa.PrivateKey) ([]byte, error)
PersonalSign signs message using EIP-191 personal_sign, returning a 65-byte signature with V in {27, 28}.
func RLPEncode ¶ added in v1.0.0
RLPEncode encodes val using Ethereum Recursive Length Prefix (RLP) encoding.
func RecoverPubkey ¶ added in v1.0.0
RecoverPubkey recovers the secp256k1 public key from a 32-byte digest and 65-byte [R || S || V] signature (accepting V in {0, 1} or {27, 28}).
func SendTransaction ¶
func SendTransaction(ctx context.Context, client Client, signedTx *Transaction) error
SendTransaction encodes and broadcasts a pre-signed Transaction.
func SignHash ¶ added in v1.0.0
func SignHash(digestHash []byte, prv *ecdsa.PrivateKey) ([]byte, error)
SignHash produces a 65-byte recoverable secp256k1 signature in [R(32) || S(32) || V(1)] format, where V is 0 or 1 (recovery ID) and S is canonical low-S (EIP-2).
func SignTransaction ¶ added in v1.0.0
func SignTransaction(tx *Transaction, chainID *big.Int, prv *ecdsa.PrivateKey) ([]byte, error)
SignTransaction signs tx with prv for the given chainID, sets From/ChainID/V/R/S/Hash on tx, and returns the raw EIP-2718 or RLP transaction wire bytes ready for eth_sendRawTransaction.
func ToECDSA ¶ added in v1.0.0
func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)
ToECDSA converts raw 32-byte secret scalar bytes into an *ecdsa.PrivateKey on secp256k1.
Types ¶
type ABI ¶ added in v1.0.0
type ABI struct {
Constructor ABIMethod
Methods map[string]ABIMethod
Overloads map[string][]ABIMethod
Events map[string]ABIEvent
Errors map[string]ABIError
}
ABI holds parsed methods, constructor, events, and custom errors of a smart contract.
func ABIBuiltIn ¶
func ABIOpenFile ¶
func ABIOpenURL ¶
func GetABI ¶
GetABI resolves a built-in ABI name ("erc20", "erc721", "erc1155", "proxy"), an inline JSON ABI array, a human-readable signature, a local file path, or an HTTP(S) URL.
func ParseABIJSON ¶ added in v1.0.0
ParseABIJSON parses a JSON ABI from reader.
func (ABI) Pack ¶ added in v1.0.0
Pack ABI-encodes a call to name (or constructor when name == "") with args.
func (ABI) ResolveMethod ¶ added in v1.0.0
ResolveMethod looks up a method by exact name, canonical signature ("transfer(address,uint256)"), or overload matching argCount when multiple methods share the same name.
type ABIArgument ¶ added in v1.0.0
type ABIArgument struct {
Name string `json:"name"`
Type ABIType `json:"-"`
RawType string `json:"type"`
InternalType string `json:"internalType,omitempty"`
Indexed bool `json:"indexed,omitempty"`
}
ABIArgument describes a named ABI input/output/event/error parameter.
type ABIArguments ¶ added in v1.0.0
type ABIArguments []ABIArgument
func (ABIArguments) Pack ¶ added in v1.0.0
func (args ABIArguments) Pack(values ...interface{}) ([]byte, error)
Pack ABI-encodes values matching the ABIArguments specification.
func (ABIArguments) UnpackValues ¶ added in v1.0.0
func (args ABIArguments) UnpackValues(data []byte) ([]interface{}, error)
UnpackValues decodes ABI-encoded output bytes according to args.
type ABIError ¶ added in v1.0.0
type ABIError struct {
Name string `json:"name"`
Inputs ABIArguments `json:"inputs"`
ID [4]byte `json:"-"` // 4-byte error selector
}
ABIError represents a Solidity custom error definition in an ABI.
type ABIEvent ¶ added in v1.0.0
type ABIEvent struct {
Name string `json:"name"`
RawName string `json:"-"`
Anonymous bool `json:"anonymous"`
Inputs ABIArguments `json:"inputs"`
ID Hash `json:"-"` // 32-byte topic0 hash
}
ABIEvent represents an event definition in an ABI.
func FindEventById ¶
FindEventById finds an event in myabi matching topic0 id, or nil if unknown.
type ABIMethod ¶ added in v1.0.0
type ABIMethod struct {
Name string `json:"name"`
RawName string `json:"-"`
Type string `json:"type"`
StateMutability string `json:"stateMutability,omitempty"`
Constant bool `json:"constant,omitempty"`
Payable bool `json:"payable,omitempty"`
Inputs ABIArguments `json:"inputs"`
Outputs ABIArguments `json:"outputs"`
ID []byte `json:"-"` // 4-byte function selector
}
ABIMethod represents a function, constructor, fallback, or receive entry in an ABI.
func ParseHumanSignature ¶ added in v1.0.0
ParseHumanSignature parses a human-readable Solidity function signature such as "transfer(address to, uint256 amount) returns (bool)" or "balanceOf(address):(uint256)".
func (ABIMethod) IsConstant ¶ added in v1.0.0
IsConstant reports whether the method is read-only (view, pure, or legacy constant: true).
type ABIType ¶ added in v1.0.0
type ABIType struct {
T byte
Size int // Bit size for int/uint (8..256), byte length for FixedBytesTy (1..32), array length for ArrayTy
Elem *ABIType // Element type for SliceTy / ArrayTy
TupleElems []ABIArgument // Fields for TupleTy
TupleRaw string // Optional internal struct name
}
ABIType represents a parsed Solidity ABI parameter type.
func ParseABIType ¶ added in v1.0.0
func ParseABIType(typeStr string, components []ABIArgument) (ABIType, error)
ParseABIType parses a Solidity ABI type string (including arrays and inline tuples like "(string,uint64)[]") with optional JSON components for "tuple" types.
func (ABIType) CanonicalString ¶ added in v1.0.0
CanonicalString returns the canonical Solidity ABI signature representation of t (used in selectors).
type AccessTuple ¶ added in v1.0.0
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
func CreateAccount ¶
func DecryptKeystore ¶ added in v1.0.0
DecryptKeystore decrypts a Web3 Secret Storage V3 keystore JSON payload into an *Account.
func NewAccountFromKey ¶ added in v1.0.0
func NewAccountFromKey(key *ecdsa.PrivateKey) *Account
func ParsePrivateKey ¶
func (*Account) Key ¶
func (a *Account) Key() *ecdsa.PrivateKey
func (*Account) PrivateKey ¶
type Address ¶ added in v1.0.0
type Address [AddressLength]byte
Address represents a 20-byte EVM account or contract address.
func BytesToAddress ¶ added in v1.0.0
BytesToAddress right-aligns b into a 20-byte Address.
func CreateAddress ¶ added in v1.0.0
CreateAddress computes the deterministic contract address deployed by caller at nonce (RLP([caller, nonce])).
func HexToAddress ¶ added in v1.0.0
HexToAddress parses a hex string (with or without 0x prefix) into an Address.
func PersonalRecover ¶ added in v1.0.0
PersonalRecover recovers the EVM address that produced an EIP-191 personal_sign signature.
func PubkeyToAddress ¶ added in v1.0.0
PubkeyToAddress derives the 20-byte EVM address from a secp256k1 public key.
func RecoverAddress ¶ added in v1.0.0
RecoverAddress recovers the signer's EVM Address from a 32-byte digest and 65-byte signature.
func RecoverTransactionSender ¶ added in v1.0.0
func RecoverTransactionSender(tx *Transaction) (Address, error)
RecoverTransactionSender recovers the sender Address from a signed Transaction.
func (Address) Hex ¶ added in v1.0.0
Hex returns the EIP-55 checksummed hex representation of the address.
func (Address) MarshalJSON ¶ added in v1.0.0
func (Address) MarshalText ¶ added in v1.0.0
func (*Address) UnmarshalJSON ¶ added in v1.0.0
func (*Address) UnmarshalText ¶ added in v1.0.0
type Block ¶
type Block struct {
ParentHash Hash
Sha3Uncles Hash
Miner Address
Signers []Address
Voters []Address
Signer []byte
StateRoot Hash
TxsRoot Hash
ReceiptsRoot Hash
LogsBloom *Bloom
Difficulty *big.Int
TotalDifficulty *big.Int
Number *big.Int
GasLimit uint64
GasUsed uint64
BaseFeePerGas *big.Int
Timestamp time.Time
ExtraData []byte
MixHash Hash
Nonce BlockNonce
Hash Hash
// Only one of TxHashes or TxDetails will be populated.
TxHashes []Hash
TxDetails []*Transaction
Uncles []Hash
}
func (*Block) ExtraVanity ¶
func (*Block) MarshalJSON ¶
func (*Block) UnmarshalJSON ¶
type BlockNonce ¶ added in v1.0.0
type BlockNonce [8]byte
BlockNonce represents an 8-byte block header nonce.
func (BlockNonce) MarshalText ¶ added in v1.0.0
func (n BlockNonce) MarshalText() ([]byte, error)
func (BlockNonce) Uint64 ¶ added in v1.0.0
func (n BlockNonce) Uint64() uint64
func (*BlockNonce) UnmarshalText ¶ added in v1.0.0
func (n *BlockNonce) UnmarshalText(input []byte) error
type Bloom ¶ added in v1.0.0
type Bloom [BloomLength]byte
Bloom represents a 2048-bit (256-byte) logs bloom filter.
func (Bloom) MarshalText ¶ added in v1.0.0
func (*Bloom) UnmarshalText ¶ added in v1.0.0
type Client ¶
type Client interface {
GetBalance(ctx context.Context, address string, blockNumber *big.Int) (*big.Int, error)
GetCode(ctx context.Context, address string, blockNumber *big.Int) ([]byte, error)
GetStorageAt(ctx context.Context, address Address, slot Hash, blockNumber *big.Int) (Hash, error)
GetBlockNumber(ctx context.Context) (uint64, error)
GetBlockByNumber(ctx context.Context, number *big.Int, includeTxs bool) (*Block, error)
GetBlockByHash(ctx context.Context, hash string, includeTxs bool) (*Block, error)
GetTransactionByHash(ctx context.Context, hash Hash) (*Transaction, error)
GetTransactionReceipt(ctx context.Context, hash Hash) (*Receipt, error)
GetLogs(ctx context.Context, q FilterQuery) ([]Log, error)
GetSnapshot(ctx context.Context) (*Snapshot, error)
GetID(ctx context.Context) (*ID, error)
GetChainID(ctx context.Context) (*big.Int, error)
GetNetworkID(ctx context.Context) (*big.Int, error)
GetGasPrice(ctx context.Context) (*big.Int, error)
MaxPriorityFeePerGas(ctx context.Context) (*big.Int, error)
EstimateGas(ctx context.Context, msg CallMsg) (uint64, error)
GetPendingTransactionCount(ctx context.Context, account Address) (uint64, error)
GetTransactionCount(ctx context.Context, account Address, blockNumber *big.Int) (uint64, error)
SendRawTransaction(ctx context.Context, tx []byte) error
Call(ctx context.Context, msg CallMsg) ([]byte, error)
Close()
SetChainID(*big.Int)
}
Client is the interface for interacting with an EVM JSON-RPC node.
type Contract ¶
type Contract struct {
Code string `json:"code"`
RuntimeCode string `json:"runtime-code"`
Info ContractInfo `json:"info"`
Hashes map[string]string `json:"hashes"`
}
Contract contains information about a compiled contract, alongside its creation and runtime bytecode.
type ContractInfo ¶
type ContractInfo struct {
Source string `json:"source"`
Language string `json:"language"`
LanguageVersion string `json:"languageVersion"`
CompilerVersion string `json:"compilerVersion"`
CompilerOptions string `json:"compilerOptions"`
SrcMap interface{} `json:"srcMap"`
SrcMapRuntime string `json:"srcMapRuntime"`
AbiDefinition interface{} `json:"abiDefinition"`
UserDoc interface{} `json:"userDoc"`
DeveloperDoc interface{} `json:"developerDoc"`
Metadata string `json:"metadata"`
}
ContractInfo contains ABI, source maps, docs, and compiler metadata for a compiled contract.
type FilterQuery ¶ added in v1.0.0
type Hash ¶ added in v1.0.0
type Hash [HashLength]byte
Hash represents a 32-byte Keccak-256 hash.
func BytesToHash ¶ added in v1.0.0
func Keccak256Hash ¶ added in v1.0.0
Keccak256Hash computes the Ethereum Keccak-256 hash and returns it as a Hash.
func PersonalMessageHash ¶ added in v1.0.0
PersonalMessageHash computes the EIP-191 personal_sign digest ("\x19Ethereum Signed Message:\n" + len + msg).
func TxSigningHash ¶ added in v1.0.0
func TxSigningHash(tx *Transaction, chainID *big.Int) (Hash, error)
TxSigningHash computes the digest hash that is signed for tx.
func (Hash) MarshalJSON ¶ added in v1.0.0
func (Hash) MarshalText ¶ added in v1.0.0
func (*Hash) UnmarshalJSON ¶ added in v1.0.0
func (*Hash) UnmarshalText ¶ added in v1.0.0
type HexBig ¶ added in v1.0.0
HexBig marshals/unmarshals big.Int as 0x-prefixed quantity hex in JSON.
func (*HexBig) MarshalText ¶ added in v1.0.0
func (*HexBig) UnmarshalText ¶ added in v1.0.0
type HexBytes ¶ added in v1.0.0
type HexBytes []byte
HexBytes marshals/unmarshals byte slices as 0x-prefixed hex strings in JSON.
func (HexBytes) MarshalText ¶ added in v1.0.0
func (*HexBytes) UnmarshalText ¶ added in v1.0.0
type HexUint64 ¶ added in v1.0.0
type HexUint64 uint64
HexUint64 marshals/unmarshals uint64 as 0x-prefixed quantity hex in JSON.
func (HexUint64) MarshalText ¶ added in v1.0.0
func (*HexUint64) UnmarshalText ¶ added in v1.0.0
type Log ¶ added in v1.0.0
type Log struct {
Address Address
Topics []Hash
Data []byte
BlockNumber uint64
TxHash Hash
TxIndex uint
BlockHash Hash
Index uint
Removed bool
}
func (Log) MarshalJSON ¶ added in v1.0.0
func (*Log) UnmarshalJSON ¶ added in v1.0.0
type RLPItem ¶ added in v1.0.0
RLPItem represents a decoded RLP element (either Bytes or a List of RLPItems).
type RPCClient ¶ added in v1.0.0
type RPCClient struct {
// contains filtered or unexported fields
}
RPCClient is a pure-Go JSON-RPC 2.0 client supporting HTTP(S) and WS(S).
func DialRPCContext ¶ added in v1.0.0
DialRPCContext connects to an HTTP(S) or WS(S) JSON-RPC endpoint using ctx.
func (*RPCClient) BatchCallContext ¶ added in v1.0.0
BatchCallContext executes a batch of JSON-RPC calls in a single round-trip.
func (*RPCClient) CallContext ¶ added in v1.0.0
func (c *RPCClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
CallContext executes a single JSON-RPC method call.
type RPCError ¶ added in v1.0.0
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
RPCError represents a JSON-RPC 2.0 error response, including optional revert data.
func (*RPCError) RevertData ¶ added in v1.0.0
RevertData extracts raw revert bytes from an RPCError if present (common on eth_call / eth_estimateGas).
type Receipt ¶
type Receipt struct {
Type uint8
PostState []byte
Status uint64
CumulativeGasUsed uint64
EffectiveGasPrice *big.Int
Bloom Bloom
Logs []*Log
TxHash Hash
TxIndex uint64
ContractAddress Address
GasUsed uint64
ParsedLogs []Event
BlockHash Hash
BlockNumber uint64
From Address
To *Address
}
func WaitForReceipt ¶
WaitForReceipt polls for a transaction receipt until available or ctx is cancelled.
func (*Receipt) MarshalJSON ¶
func (*Receipt) UnmarshalJSON ¶
type Solidity ¶
type Solidity struct {
Path, Version, EVMVersion string
Major, Minor, Patch int
Optimize bool
UseDocker bool
}
Solidity specifies the Solidity compiler configuration.
func SolidityVersion ¶
SolidityVersion extracts a concrete Solidity compiler version from pragma solidity in source.
type Transaction ¶
type Transaction struct {
Type uint8
ChainID *big.Int
Nonce uint64
GasPrice *big.Int // wei (Legacy / EIP-2930, or effective gasPrice returned by RPC)
MaxPriorityFeePerGas *big.Int // wei (EIP-1559)
MaxFeePerGas *big.Int // wei (EIP-1559)
GasLimit uint64
To *Address
Value *big.Int // wei
Input []byte
AccessList []AccessTuple
From Address
V *big.Int
R *big.Int
S *big.Int
Hash Hash
BlockNumber *big.Int
BlockHash Hash
TransactionIndex uint64
}
func CallFunctionWithArgs ¶ added in v0.2.69
func CallFunctionWithArgs(ctx context.Context, client Client, privateKeyHex, address string, amount *big.Int, gasPrice *big.Int, gasLimit uint64, myabi ABI, functionName string, params ...interface{}) (*Transaction, error)
CallFunctionWithArgs submits a contract transaction with legacy gasPrice/gasLimit parameters (0 gasLimit auto-estimates).
func CallFunctionWithData ¶ added in v0.2.69
func CallFunctionWithData(ctx context.Context, client Client, privateKeyHex, address string, amount *big.Int, gasPrice *big.Int, gasLimit uint64, data []byte) (*Transaction, error)
CallFunctionWithData submits pre-encoded calldata to address.
func CallFunctionWithDataOpts ¶ added in v1.0.0
func CallFunctionWithDataOpts(ctx context.Context, client Client, privateKeyHex, address string, opts TxOptions, data []byte) (*Transaction, error)
CallFunctionWithDataOpts submits pre-encoded calldata to address with full TxOptions.
func CallFunctionWithOpts ¶ added in v1.0.0
func CallFunctionWithOpts(ctx context.Context, client Client, privateKeyHex, address string, opts TxOptions, myabi ABI, functionName string, params ...interface{}) (*Transaction, error)
CallFunctionWithOpts submits a contract transaction supporting EIP-1559 fees, auto gas estimation, and revert decoding.
func CallTransactFunction ¶
func CallTransactFunction(ctx context.Context, client Client, myabi ABI, address, privateKeyHex, functionName string, amount *big.Int, gasPrice *big.Int, gasLimit uint64, params ...interface{}) (*Transaction, error)
CallTransactFunction submits a transaction to execute a smart contract function call. Deprecated: prefer CallFunctionWithArgs or CallFunctionWithOpts.
func DeployBin ¶
func DeployBin(ctx context.Context, client Client, privateKeyHex, binFilename, abiFilename string, gasPrice *big.Int, gasLimit uint64, constructorArgs ...interface{}) (*Transaction, error)
DeployBin deploys a .bin file (local path or URL) with optional .abi file and constructor arguments.
func DeployContract ¶
func DeployContract(ctx context.Context, client Client, privateKeyHex, binHex, abiJSON string, gasPrice *big.Int, gasLimit uint64, constructorArgs ...interface{}) (*Transaction, error)
DeployContract submits a contract creation transaction (0 gasLimit auto-estimates).
func DeployContractWithOpts ¶ added in v1.0.0
func DeployContractWithOpts(ctx context.Context, client Client, privateKeyHex, binHex, abiJSON string, opts TxOptions, constructorArgs ...interface{}) (*Transaction, error)
DeployContractWithOpts submits a contract creation transaction with full TxOptions.
func DeployEIP1967Proxy ¶ added in v1.0.0
func DeployEIP1967Proxy(ctx context.Context, client Client, privateKeyHex string, implementationAddr, adminAddr Address, initData []byte, opts TxOptions) (*Transaction, error)
DeployEIP1967Proxy deploys a standard EIP-1967 upgradeable proxy pointing at implementationAddr with optional initData.
func Send ¶
func Send(ctx context.Context, client Client, privateKeyHex string, to Address, amount *big.Int, gasPrice *big.Int, gasLimit uint64) (*Transaction, error)
Send performs a native coin transfer (GO/ETH).
func SendWithOpts ¶ added in v1.0.0
func SendWithOpts(ctx context.Context, client Client, privateKeyHex string, to Address, opts TxOptions) (*Transaction, error)
SendWithOpts performs a native coin transfer supporting EIP-1559 and auto gas estimation.
func (*Transaction) MarshalJSON ¶
func (t *Transaction) MarshalJSON() ([]byte, error)
func (*Transaction) UnmarshalJSON ¶
func (t *Transaction) UnmarshalJSON(data []byte) error
type TxOptions ¶ added in v1.0.0
type TxOptions struct {
Value *big.Int
GasPrice *big.Int // Explicit legacy gasPrice (wei)
MaxFeePerGas *big.Int // Explicit EIP-1559 maxFeePerGas (wei)
MaxPriorityFeePerGas *big.Int // Explicit EIP-1559 maxPriorityFeePerGas (wei)
GasLimit uint64 // 0 = auto-estimate via eth_estimateGas
Nonce *uint64 // nil = auto-fetch pending nonce
}
TxOptions configures gas fees, gas limit, value, and nonce when submitting a transaction.