What is an ABI?

Smart contract code is written in human-readable languages, such as Solidity and Vyper. When compiled and stored on the Ethereum Virtual Machine (EVM), it is converted into bytecode, a machine-recognizable format.

Attempting to read and write smart contracts on Ethereum without an interface to translate between human and machine-readable language would make interaction with the smart contracts difficult.

An ABI (Application Binary Interface) serves as an interface that translates human-readable instructions (function calls and parameters) into machine-executable code (calldata) and vice versa.

With the ABI, smart contracts can communicate with other applications and smart contracts. The ABI is produced by a smart contract compiler, outlining the entire scope of functions a smart contract has, the types of arguments those functions take, and the kind of values they return.

Source: medium.com/@eiki1212

For example, when a user wants to initiate an ERC-20 transfer, they will call the function transfer(address _to, uint _value) public. The ABI will send a message in the form of bytecode, such as 0xa9059cbb0000000000000000000000000320b7c5b1c31d43de7ea9d13fbf9ff82067585d00000000000000000000000000000000000000000000000000000000af79e000, to the smart contract for execution.

Understanding what a smart contract is doing is possible without reading the code, simply by referring to the ABI. The ABI for the function call as represented in JSON:

{
    "constant":false,
    "inputs":[
                {
                    "name":"_to",
                    "type":"address"
                },
                {
                    "name":"_value",
                    "type":"uint256"
                }
             ],
    "name":"transfer",
    "outputs":[],
    "payable":false,
    "stateMutability":"nonpayable",
    "type":"function"
}

You can obtain the ABI of a verified contract on Etherscan under the code tab.
For example:

Click image to view it on Etherscan

Further reading:

  • Teck Yuan Lee
Updated