ABI (Application Binary Interface)
An ABI (Application Binary Interface) defines a standard way to interact with contracts (i.e. it defines the calling conventions to use for message calls).
More concretely this entails:
- Specifications for generating selectors which identify the entry points for message/function calls
- Specifications for encoding and decoding message/function arguments and return types, as well as event and error argument types
With ink! v6, the ink! code generator supports two ABI specifications:
Supporting the Solidity ABI specification allows:
- Solidity contracts to transparently call ink! contracts
- Developers to use Solidity tools (e.g. ethers.js) to transparently interact with ink! contracts.
Additionally, the ink! code generator can operate in an "all"
ABI mode,
where it generates a binary that supports both the ink! and Solidity ABI specifications
(i.e. it generates a binary that transparently supports both ink! and Solidity
calling conventions, and thus transparently supports interactions from
both ink! and Solidity contracts and external tools).
Declaring the ABI
The ABI for an ink! contract is declared in the contract's manifest file
(i.e. the Cargo.toml
file), as a field abi
of a custom ink-lang
table
in the package.metadata
table e.g.
[package.metadata.ink-lang]
abi = "sol"
The default value for abi
is "ink"
.
Allowed values are "ink"
, "sol"
and "all"
.
The Solidity ABI specification can only be used if all constructor and message argument and return types, and event argument types can be mapped to equivalent Solidity ABI types (more details here).
Your contract sizes will get larger if you support both the ink! and Solidity ABI.