parallax/cmd/abigen
and running go build
, or equivalently:
What is an ABI?
Parallax smart contracts have a schema that defines its functions and return types in the form of a JSON file. This JSON file is known as an Application Binary Interface, or ABI. The ABI acts as a specification for precisely how to encode data sent to a contract and how to decode the data the contract sends back. The ABI is the only essential piece of information required to generate Go bindings. Go developers can then use the bindings to interact with the contract from their Go application without having to deal directly with data encoding and decoding. An ABI is generated when a contract is compiled.Generating the bindings
To demonstrate the binding generator a contract is required. The contractStorage.sol
implements two very simple functions: store
updates a user-defined uint256
to the contract’s storage, and retrieve
displays the value stored in the contract to the user. The Solidity code is as follows:
Storage.sol
. The following code snippet shows how an ABI can be generated for Storage.sol
using the Solidity compiler solc.
Storage.sol
(Storage.abi
) looks as follows:
--abi
: Mandatory path to the contract ABI to bind to--pkg
: Mandatory Go package name to place the Go code into--type
: Optional Go type name to assign to the binding struct--out
: Optional output path for the generated Go source file (not set = stdout)
Storage.go
contains all the bindings required to interact with Storage.sol
from a Go application.
For instructions on how to deploy this contract to Parallax from a Go native application read our Go bindings page. To browse the Abigen source code visit the Parallax client GitHub repository.