ABIs: How We Tell Smart Contracts What to Do - A Simple Explanation


Transaction Calldata

When someone performs a transaction with a smart contract, that transaction will include some data about itself in a section called “calldata.” This calldata determines which of the smart contracts functions are being used.

Information in the “calldata” section is expressed in bytecode, the language that smart contracts are expressed in on the blockchain. ABIs allow transactions to provide instructions in bytecode so that we can tell smart contracts what to do, in the language they understand.


ABIs (Application Binary Interfaces)

An ABI standardizes how to translate instructions into bytecode. Once in bytecode, instructions appear as one long string of characters, but there is a structure that’s useful to understand.

  • First 4 Bytes: The first 4 bytes, or 8 characters, in a transaction’s calldata section determine which function is being called in a smart contract. For example, the “mint” function.
  • From the 5th Byte On: This is where any additional data is provided that the transaction may need. For example, how many tokens to mint.

Source: Alberto Molina

Using the ABI Database

Since the first 4 bytes determine the function that’s being called, this information can be used to verify what a transaction is doing. The first 8 characters can be pasted into this database, which will give you information you can use to verify the transaction is performing an expected function.

Step 1: When presented with a transaction, click on “View full transaction details.”


Step 2: Copy the first 8 characters.


Step 3: Go to the Function Signatures tab on 4byte.directory and paste those 8 characters into the search bar.


In this example, two results appear in our search. Since only 4 bytes are used to represent the function, some functions may share these first 4 bytes.

ABIs in the Ethereum Ecosystem

ABIs standardize how information to smart contracts should be structured, but they aren’t a part of the core Ethereum protocol (as opposed to the consensus algorithm, for example). The Ethereum protocol and EVM only look at the bytecode inputs, so ABIs that translate instructions into bytecode exist purely for our convenience. They are extremely useful in allowing us to perform smart contract operations easily.

This post is a summary of the full write-up on my newsletter. Check it out below!

Sign up to receive a simple explanation of a blockchain concept, delivered once a week.

Stay kind. Stay curious. 😶‍🌫️