Skip to main content
Two packages handle the account layer in go-ethereum:
  • accounts/abi — encode method calls, decode return values, and parse event logs.
  • accounts/keystore — create, import, unlock, and sign with password-encrypted key files.

accounts/abi

The ABI type

Parsing an ABI

Encoding a method call

Pack prepends the 4-byte selector and ABI-encodes all arguments:
Pass an empty name to encode constructor arguments only (no selector):

Decoding return values

Unpack returns []interface{}; UnpackIntoInterface maps values into a struct or slice:

Parsing event logs

Events are accessed through abi.Events:
Indexed event parameters are packed into log.Topics (32 bytes each), not into log.Data. Non-indexed parameters are ABI-encoded in log.Data.

Looking up methods and events by selector

Decoding revert reasons

Passes raw revert data (from CallContract errors or receipt logs) and returns the human-readable reason string from a Solidity revert("...") or a panic code description.

Full example — call + decode


accounts/keystore

Keys are stored as encrypted JSON files using the Web3 Secret Storage specification.

Scrypt parameters

Two predefined cost settings trade security for speed:

Creating a keystore

Creating an account

Importing a raw private key

Unlocking and signing a transaction

If you do not want to keep the key unlocked in memory, use SignTxWithPassphrase instead — it decrypts the key on demand and zeroes it immediately after signing.

Sign without unlocking

Listing and locking accounts

Importing / exporting encrypted JSON keys