abigen
SYNOPSIS
abigen [options]
PARAMETERS
--abi string
ABI JSON file or directory slug (default '-')
--alias strings
Add a type definition (e.g. MyType=OtherType)
--bin string
Binary file or directory slug (default '-')
--include strings
Comma-separated list of packages to always include (-)
--lang string
Target language (go|java) (default 'go')
--out string
Output file name (default '-')
--pkg string
Go package name (default 'main')
--sol string
Solidity file or directory slug (default '-')
--type string
Contract type to generate into (default '*')
DESCRIPTION
abigen is a command-line tool from the go-ethereum project used to generate idiomatic Go code for interacting with Ethereum smart contracts. It takes Ethereum contract ABIs (in JSON format), optional bytecode, and Solidity source files as input, producing Go packages that wrap contract calls as native method invocations.
This enables developers to deploy, call, and transact with contracts using familiar Go syntax, handling ABI encoding/decoding automatically. For Solidity files (--sol), it internally invokes solc to compile and extract ABIs. Supports both Go (--lang go) and Java (--lang java) output. Primarily used in Ethereum dApp development with tools like Geth.
Installation typically via go install github.com/ethereum/go-ethereum/cmd/abigen@latest. Essential for type-safe contract interactions without manual ABI handling.
CAVEATS
Requires Go compiler and solc for Solidity input. Output overwrites files without warning. Not for production binaries; regenerate on ABI changes.
BASIC EXAMPLE
abigen --abi MyContract.abi --pkg mycontract --type MyContract --out mycontract.go
Generates MyContract struct with Deploy, Transact, and Call methods.
FROM SOLIDITY
abigen --sol MyContract.sol --pkg mycontract --out mycontract.go
Compiles Solidity, extracts ABI/bin, generates bindings.
HISTORY
Developed as part of go-ethereum (Geth) client since ~2015. Evolved with Ethereum upgrades like Constantinople (2019) for new opcodes. Actively maintained by Ethereum Foundation.


