Documentation
¶
Overview ¶
Package abi provides ABI encoding and decoding for TRON smart contracts.
Index ¶
- func DecodeOutput(contractABI *core.SmartContract_ABI, method string, data []byte) ([]interface{}, error)
- func DecodeRevertReason(data []byte) (string, error)
- func FormatABI(abi *core.SmartContract_ABI) []map[string]any
- func FormatABIEntry(entry *core.SmartContract_ABI_Entry) map[string]any
- func GetEventParser(ABI *core.SmartContract_ABI, event string) (indexed eABI.Arguments, nonIndexed eABI.Arguments, err error)
- func GetInputsParser(ABI *core.SmartContract_ABI, method string) (eABI.Arguments, error)
- func GetPaddedParam(param []Param) ([]byte, error)
- func GetParser(ABI *core.SmartContract_ABI, method string) (eABI.Arguments, error)
- func Pack(method string, param []Param) ([]byte, error)
- func ParseTopicsIntoMap(out map[string]interface{}, fields eABI.Arguments, topics [][]byte) error
- func Signature(method string) []byte
- type Param
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeOutput ¶ added in v0.24.3
func DecodeOutput(contractABI *core.SmartContract_ABI, method string, data []byte) ([]interface{}, error)
DecodeOutput decodes ABI-encoded output bytes from a constant contract call into a slice of typed values. Addresses are automatically converted from Ethereum format to TRON base58 format.
func DecodeRevertReason ¶ added in v0.24.3
DecodeRevertReason extracts the human-readable error string from ABI-encoded revert data. Supports both Error(string) (selector 0x08c379a0) from revert/require and Panic(uint256) (selector 0x4e487b71) from assertion failures and arithmetic errors.
func FormatABI ¶ added in v0.24.3
func FormatABI(abi *core.SmartContract_ABI) []map[string]any
FormatABI converts an entire proto SmartContract_ABI into a slice of human-readable maps suitable for JSON serialization. A nil ABI returns an empty slice.
func FormatABIEntry ¶ added in v0.24.3
func FormatABIEntry(entry *core.SmartContract_ABI_Entry) map[string]any
FormatABIEntry converts a single proto ABI entry into a map using human-readable string labels for type and stateMutability, matching the canonical Ethereum ABI JSON format. Fields that are not applicable to a given entry type are omitted (e.g., events have no outputs). A nil entry returns an empty map.
func GetEventParser ¶ added in v0.24.2
func GetEventParser(ABI *core.SmartContract_ABI, event string) (indexed eABI.Arguments, nonIndexed eABI.Arguments, err error)
GetEventParser returns indexed and non-indexed argument lists for an ABI event.
func GetInputsParser ¶
GetInputsParser returns the input argument definitions for the given method, used to decode call data.
func GetPaddedParam ¶
GetPaddedParam ABI-encodes a slice of Param into padded bytes suitable for contract calls.
func GetParser ¶
GetParser returns the output argument definitions for the given method, used to decode return data.
func Pack ¶
Pack encodes a method call by prepending the 4-byte function selector to the ABI-encoded parameters.
func ParseTopicsIntoMap ¶ added in v0.24.2
ParseTopicsIntoMap parses event log topics into a map with automatic Ethereum-to-TRON address conversion. The topics slice should not include the event signature hash (topics[0]); pass only the indexed parameter topics.
Types ¶
type Param ¶
type Param map[string]interface{}
Param represents a single ABI parameter as a type→value mapping (e.g. {"address": "T..."}).
func LoadFromJSON ¶
LoadFromJSON parses a JSON array of typed-object parameters into a Param slice. Each JSON element must be an object with a single key (the ABI type) and value.
func LoadFromJSONWithMethod ¶ added in v0.25.2
LoadFromJSONWithMethod parses a JSON parameter string, automatically inferring parameter types from the method signature when the JSON contains plain values (strings/numbers) instead of typed objects.
Plain-value format (new):
method: "transfer(address,uint256)" json: `["TJDENsfBJs4RFETt1X1W8wMDc8M5XnS5f4", "1000000"]`
Typed-object format (existing, still supported):
json: `[{"address": "TJDENsfBJs4RFETt1X1W8wMDc8M5XnS5f4"}, {"uint256": "1000000"}]`
Detection: if the first JSON array element is a string or number, the plain-value format is assumed and types are inferred from the method signature. If the first element is an object, the typed-object format is used (passthrough to LoadFromJSON).