MultiversX Tracker is Live!

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

Etherum Reddit

More / Etherum Reddit 78 Views

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.

https://preview.redd.it/pwil82lp0sia1.png?600&format=png&auto=webp&s=f2a1f4f6935582730bed829615173f5f888dad05

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.”

https://preview.redd.it/lm20c0b41sia1.jpg?380&format=pjpg&auto=webp&s=be9c0659239d683f25430dcc84eaf821546e0239

Step 2: Copy the first 8 characters.

https://preview.redd.it/zj61zsa61sia1.jpg?380&format=pjpg&auto=webp&s=0ec6ff5fdfb35d65e559c742e142633f9bb654f9

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

https://preview.redd.it/iyr0b1r71sia1.jpg?1280&format=pjpg&auto=webp&s=985d2b4749e9af2374e9aea1762ed339d1cedbaa

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. ????‍????️

https://ramiwrites.substack.com/p/abis-how-we-tell-smart-contracts?sd=pf

submitted by /u/phillistine
[link] [comments]

Get BONUS $200 for FREE!

You can get bonuses upto $100 FREE BONUS when you:
💰 Install these recommended apps:
💲 SocialGood - 100% Crypto Back on Everyday Shopping
💲 xPortal - The DeFi For The Next Billion
💲 CryptoTab Browser - Lightweight, fast, and ready to mine!
💰 Register on these recommended exchanges:
🟡 Binance🟡 Bitfinex🟡 Bitmart🟡 Bittrex🟡 Bitget
🟡 CoinEx🟡 Crypto.com🟡 Gate.io🟡 Huobi🟡 Kucoin.



Comments