What is an ABI of a Smart Contract? (2024)

The Application Binary Interface (ABI) of a smart contract gives a contract the ability to communicate and interact with external applications and other smart contracts. Receiving data from external sources can be critical for completing the goals of the application and the user.

In traditional web development, conversations about data happen between applications and servers through API's (Application Program Interface). Servers act as centralized sources of information that feed data to application by request.

On a blockchain, no such centralization of data exists. Nodes essentially act as servers and smart contracts are on chain "hosted" functions. Applications outside of the blockchain (and other smart contracts) need a way to communicate with smart contracts that are on-chain. This is where ABI comes into play.

Before going into more details about what ABI is, it is good to understand why we have it.

Smart contracts are the core applications of the EVM (Ethereum Virtual Machine). The purpose of smart contracts is to execute transactions when certain conditions defined in the contract are met. These conditions can be events both on or off-chain. Smart contracts are written in high-level languages like Solidity but they are stored on the EVMas executable bytecode, which is in binary format.

What is an ABI of a Smart Contract? (3)

Since this bytecode is not human readable, it requires interpretation to be understood. ABI allows anyone writing a smart contract to be able to communicate between a web application written in a high-level language like Javascript and the bytecode that the EVM understands.

What is an ABI?

Like its Web2 cousin, the API, ABI acts as a function selector, defining the specific methods that can be called to a smart contract for execution. These specific methods and their connected data types are listed in a generated JSON RPC file.

What is an ABI of a Smart Contract? (4)

Unlike an API, we can't just send a request directly in JSON format to a smart contract and expect a response since a contract only communicates in bytecode. To translate this into something the EVM understands, this information is encoded via ABI encoding. These encodings include function signatures and variable declarations so that the EVM knows exactly which function to execute within the smart contract.

What is an ABI of a Smart Contract? (5)

The responses are also in the bytecode so interpretation is required before it is processed by a web application. The advantage of using bytecode in the response is that we can also expect a certain structure to be returned after calling a contract's function.

Generation

If you are using tooling like Hardhart/Truffle or an IDE like Remix, the contract ABI is automatically generated for you. You can also manually create the ABI by using the Solidity Compiler NPM package. After installing the package, you can run the ‘solcjs contractname.sol --abi’ command in a terminal. This will generate an .abi file if performed successfully.

Now that you have a generated ABI, let's look at some of the elements in this file:

What is an ABI of a Smart Contract? (6)

Executing

As ABI operates as the interpreter between the EVM bytecode and Javascript of a website, it is needed when you want to execute any functions of a smart contract. In addition to the ABI, the contract's address on the blockchain is required. Here is a small Javascript code snippet to show how this is done:

What is an ABI of a Smart Contract? (7)

If you are interested in finding the ABI of an already deployed contract, you can find this by searching on Etherscan with the contract's address. For example here:

What is an ABI of a Smart Contract? (8)

Encoding

Since all communication is done in bytecode, it would be difficult to expect developers to encode these messages themselves. Fortunately, popular compilers like Remix can also handle the encoding for you. These encodings follow a certain pattern, so one can have a better idea of what is going on by reviewing the ABI Specification.

The first four bytes are the function signature which indicates what type of function in the smart contract is being executed. A popular function identifier is a9059cbb which indicates that this is an ERC20 transfer. There is a database directory of function signatures here where you can explore more.

What is an ABI of a Smart Contract? (9)

From the fifth byte onward are where the arguments are encoded. Responses follow this similar structure but without the function signature included.

Conclusion

ABI can oftentimes be an overlooked aspect of working with smart contracts but it plays an important role in the usability of this technology. Building on smart contract tutorials is a great way to understand the power of this silent workhorse and a great way to apply your knowledge.

What is an ABI of a Smart Contract? (2024)
Top Articles
What happens if my key expires?
Profit
Jack Doherty Lpsg
Fan Van Ari Alectra
Craigslist Cars Augusta Ga
Farepay Login
Kaydengodly
Hotels Near 500 W Sunshine St Springfield Mo 65807
Doby's Funeral Home Obituaries
Jasmine
Detroit Lions 50 50
Items/Tm/Hm cheats for Pokemon FireRed on GBA
Classroom 6x: A Game Changer In The Educational Landscape
The Shoppes At Zion Directory
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Dutchess Cleaners Boardman Ohio
The Witcher 3 Wild Hunt: Map of important locations M19
25Cc To Tbsp
Pizza Hut In Dinuba
Everything you need to know about Costco Travel (and why I love it) - The Points Guy
Tu Pulga Online Utah
55Th And Kedzie Elite Staffing
Labcorp.leavepro.com
1979 Ford F350 For Sale Craigslist
Violent Night Showtimes Near Johnstown Movieplex
New Stores Coming To Canton Ohio 2022
Dexter Gomovies
Select The Best Reagents For The Reaction Below.
How Much Is An Alignment At Costco
Wega Kit Filtros Fiat Cronos Argo 1.8 E-torq + Aceite 5w30 5l
2024 Coachella Predictions
Kstate Qualtrics
How does paysafecard work? The only guide you need
4083519708
Leatherwall Ll Classifieds
Arcadia Lesson Plan | Day 4: Crossword Puzzle | GradeSaver
Enjoy4Fun Uno
Is Arnold Swansinger Married
Blackwolf Run Pro Shop
Go Bananas Wareham Ma
Carroll White Remc Outage Map
Actor and beloved baritone James Earl Jones dies at 93
18006548818
Dragon Ball Super Super Hero 123Movies
Collision Masters Fairbanks
Yale College Confidential 2027
Scott Surratt Salary
300+ Unique Hair Salon Names 2024
Freightliner Cascadia Clutch Replacement Cost
Steam Input Per Game Setting
Erica Mena Net Worth Forbes
Superecchll
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6120

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.