abi

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: LGPL-3.0 Imports: 14 Imported by: 24

Documentation

Overview

Package abi provides ABI encoding and decoding for TRON smart contracts.

Index

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

func DecodeRevertReason(data []byte) (string, error)

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

func GetInputsParser(ABI *core.SmartContract_ABI, method string) (eABI.Arguments, error)

GetInputsParser returns the input argument definitions for the given method, used to decode call data.

func GetPaddedParam

func GetPaddedParam(param []Param) ([]byte, error)

GetPaddedParam ABI-encodes a slice of Param into padded bytes suitable for contract calls.

func GetParser

func GetParser(ABI *core.SmartContract_ABI, method string) (eABI.Arguments, error)

GetParser returns the output argument definitions for the given method, used to decode return data.

func Pack

func Pack(method string, param []Param) ([]byte, error)

Pack encodes a method call by prepending the 4-byte function selector to the ABI-encoded parameters.

func ParseTopicsIntoMap added in v0.24.2

func ParseTopicsIntoMap(out map[string]interface{}, fields eABI.Arguments, topics [][]byte) error

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.

func Signature

func Signature(method string) []byte

Signature returns the 4-byte Keccak-256 function selector for the given method signature.

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

func LoadFromJSON(jString string) ([]Param, error)

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

func LoadFromJSONWithMethod(method, jString string) ([]Param, error)

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).

Jump to

Keyboard shortcuts

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