viem-goviem-go

Contract Utilities

Encode and decode helpers used by contract actions

Contract actions (readContract, writeContract, getContractEvents, etc.) use ABI encoding and decoding under the hood. You can use the same utilities directly when building custom calldata, decoding return data, or parsing event logs.

Where they live

UtilityPackage / APIDoc
encodeFunctionDataclient.EncodeFunctionData(opts) or abi.EncodeFunctionData on *ABIABI Encoding
decodeFunctionDataabi.DecodeFunctionData on *ABIABI Decoding
decodeFunctionResultabi.DecodeFunctionResult on *ABIABI Decoding
encodeEventTopicsabi.EncodeEventTopics on *ABIABI Encoding
decodeEventLogabi.DecodeEventLog / DecodeEventLogByName on *ABIABI Decoding
encodeErrorResultabi.EncodeErrorResult on *ABIABI Encoding
decodeErrorResultabi.DecodeErrorResult on *ABIABI Decoding
encodeFunctionResultabi.EncodeFunctionResult on *ABIABI Encoding
parseEventLogsabi.ParseEventLogs on *ABISelectors & Items
encodeDeployDataBytecode + abi.EncodeConstructor(args...)Deploy Contract, ABI Encoding
decodeDeployDataDecode constructor args from deploy data: use abi.DecodeFunctionArgsFromData with constructor “function” or decode with DecodeAbiParameters and constructor input paramsABI Decoding, ABI Decode Parameters

Client-level helpers

  • client.EncodeFunctionData(EncodeFunctionDataOptions) — encode calldata from ABI (string/bytes), function name, and args. Uses abi.Parse and EncodeFunctionData internally. Use when you don’t have a parsed *ABI.
  • client.DecodeFunctionResult(DecodeFunctionResultOptions) — decode return data from ABI, function name, and raw data. Use when you don’t have a parsed *ABI.

For all other helpers (with a parsed *abi.ABI), use the abi package as in the table above. Standalone parameter encode/decode (no ABI) is in the ABI section: EncodeAbiParameters, DecodeAbiParameters, EncodePacked.

See also