What is an ABI?
An ABI (Application Binary Interface) traditionally defines the interface between two binary program modules. In the context of the NEAR ABI, this JSON schema defines the interface to the Wasm binary (smart contract) on the NEAR network, including parameter and result formats used through the NEAR runtime.
Why do we need ABI?
- Human-readable format to easy indicate how to interact with the contract
- Standard interface definition cross-language
- Ability to be used with any combination of contract SDK and client libraries
- Tooling built using the ABI to be able to generate code to interact with any contract easily
Ensure you have cargo-near installed
To generate an ABI for a contract within the directory containing contract's Cargo.toml
$ cargo near abi
Ensure that the project you are generating an ABI for depends on a version of near-sdk
of 4.1.0
or later and has the abi
feature enabled.
near-sdk = { version = "4.1.0", features = ["abi"] }
Ensure you have a near-sdk-js (version 0.7.0 or later) contract
To generate an ABI for a contract within the directory containing contract's package.json
$ npx near-sdk-js build --generateABI path/to/contract.ts
The ABI will be put in build/contract-abi.json
- near-sdk-rs (version
4.1.0
and above) and cargo-near (version0.3.0
and above):cargo-near
is a cargo extention that is used to build the contract and generate the ABI from anear-sdk-rs
contract. - near-sdk-js (version
0.7.0
and above): invokenear-sdk-js build
with--generateABI
to generate the ABI from a TypeScript contract (pure JavaScript is not supported yet).
- near-abi-client-rs: Generates glue code to interact with contracts through RPC using workspaces-rs.
- near-sdk-abi: Generates near-sdk-rs glue code to make cross-contract calls within other contracts.
- near-api-js: integration with NAJ is coming soon, stay tuned.
- near-abi-rs: Common Rust types used across Rust ABI crates.
- near-abi-js: Common types used across JavaScript ABI libraries.