EIP-2069 · Stagnant · Informational · 2017-02-11
EIP-2069: Recommendation for using YAML ABI in ERCs/EIPs
An informational recommendation that EIPs and ERCs describe contract interfaces as YAML-formatted ABI, which is language-neutral like JSON but allows comments, instead of as Solidity code.
What problem does it solve?
Most interface standards, such as ERC-20, present their API as a Solidity interface. The author points out three drawbacks:
- It favours one language and can disadvantage others (Vyper, Fe, hand-written bytecode, off-chain tooling).
- It ties the spec to a particular Solidity version and syntax, which changes over time.
- Solidity can express things that do not map cleanly onto the ABI, which puts other languages at a further disadvantage.
The neutral description of a contract interface is the Contract ABI, normally written as JSON. But JSON cannot contain comments, and a specification needs explanations next to each function.
How it works
The recommendation is simple: write the ABI in YAML. YAML is a superset of JSON, so the content is the same ABI that compilers and libraries already understand, and converting between the two is mechanical. Unlike JSON, YAML allows # comments, so authors can document each function inline.
Authors are encouraged to add comments to the YAML ABI. The allowed fields and values are exactly those in the Solidity Contract ABI specification; this EIP does not invent a new description language. The spec points to yamabi, a JavaScript tool for converting between YAML and JSON ABI.
Sample code
The spec's example, a transfer function in YAML:
# The transfer function. Takes the recipient address
# as an input and returns a boolean signaling the result.
- name: transfer
type: function
stateMutability: nonpayable
inputs:
- name: recipient
type: address
- name: amount
type: uint256
outputs:
- name: ''
type: bool
Loading it into ethers v6 (any YAML parser works; the result is a normal JSON ABI):
import { readFileSync } from "node:fs";
import { parse } from "yaml";
import { Interface } from "ethers";
const abi = parse(readFileSync("transfer.abi.yaml", "utf8"));
const iface = new Interface(abi);
console.log(iface.getFunction("transfer")!.selector); // "0xa9059cbb"
Things to know
- Status is Stagnant. It is an Informational recommendation, not a requirement, and in practice most ERCs still present interfaces in Solidity.
- The spec's YAML example also includes the legacy
payableandconstantfields; current ABI output usesstateMutabilityalone, which is why they are omitted above. - Comments are dropped when converting YAML to JSON, so keep the YAML file as the documented source of truth.