← 返回命令列表

Linux command

abigen 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Generate

abigen --abi [contract.abi] --pkg [packagename] --out [contract.go]

Example

abigen --bin [contract.bin] --abi [contract.abi] --pkg [packagename] --out [contract.go]

Example

abigen --sol [contract.sol] --pkg [packagename] --out [contract.go]

Example

abigen --abi [contract.abi] --pkg [packagename] --type [MyContract] --out [contract.go]

说明

abigen is an Ethereum tool that generates Go language bindings for interacting with smart contracts. It takes a contract's ABI (Application Binary Interface) and optionally its bytecode to produce type-safe Go code for deploying and calling contract methods. The generated code handles ABI encoding/decoding, transaction creation, and event filtering, making it straightforward to interact with Ethereum contracts from Go applications. This eliminates the need for manual ABI manipulation and provides compile-time type checking.

参数

--abi _file_
Path to the contract ABI JSON file
--bin _file_
Path to the contract bytecode (required for deployment code generation)
--sol _file_
Path to Solidity source file (requires solc compiler)
--pkg _name_
Package name for the generated Go code
--out _file_
Output file path for generated code
--type _name_
Struct name for the contract binding (defaults to contract name)
--lang _language_
Target language for generated bindings (default: go).
--solc _path_
Solidity compiler path when using --sol.
--combined-json _file_
Path to the combined-json output from solc compiler.
--alias _aliases_
Comma-separated list of identifier aliases (original=replacement).

FAQ

What is the abigen command used for?

abigen is an Ethereum tool that generates Go language bindings for interacting with smart contracts. It takes a contract's ABI (Application Binary Interface) and optionally its bytecode to produce type-safe Go code for deploying and calling contract methods. The generated code handles ABI encoding/decoding, transaction creation, and event filtering, making it straightforward to interact with Ethereum contracts from Go applications. This eliminates the need for manual ABI manipulation and provides compile-time type checking.

How do I run a basic abigen example?

Run `abigen --abi [contract.abi] --pkg [packagename] --out [contract.go]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --abi _file_ do in abigen?

Path to the contract ABI JSON file