Application Binary Interface (ABI )

ABI stands for Application Binary Interface. In the context of Solidity, ABI is used to describe the interface of a smart contract - that is, the set of functions, events, and variables that are exposed and can be accessed by other contracts or external applications.

ABI provides a standard way for contracts to communicate with each other and for external applications to interact with contracts. It defines the structure of the data that is passed to and from contracts, including the types of variables, function names, and argument lists.

ABI also plays a critical role in contract deployment and execution, as it is used to encode and decode transaction data, ensuring that the data is correctly formatted and can be processed by the Ethereum Virtual Machine (EVM).

The ABI indicates to the caller of a contract function how to encode the needed information, such as function signatures and variable declarations, in such a way that the EVM knows how to communicate that call to the deployed contract's bytecode.

In order to interact with a smart contract on the Ethereum blockchain, a web application needs the contract's address and ABI.

See the example on Etherscan

Example

[
  {
    "inputs": [
      { "internalType": "string", "name": "message", "type": "string" }
    ],
    "name": "setMessage",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "getMessage",
    "outputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  }
]

This ABI describes a smart contract that has two functions: setMessage and getMessage. setMessage takes in a string parameter called message and does not return anything. getMessage does not take any parameters and returns a string.

The ABI is an array of objects, where each object describes a function in the smart contract. For each function, the object includes the function name, input parameters, output parameters, and the function's state mutability.

The ABI is used by other applications to interact with the smart contract, so they can understand how to call its functions and retrieve data from it.

Last updated