🔲Ethereum Contract ABI Specification thread

What is ABI?

Good morning.

Today spent a few hours reading the Ethereum contract ABI specification and I summarized the main parts in this thread.

For further reading, refer to the official docs.

Table of contents

Basic Design
Assumptions
Function Encoding
Types
Tuples
Mapping Solidity to ABI types
Encoding design criteria
Static and Dynamic types
Contract Application Binary Interface (ABI)

It's the standard way to interact with contracts in the Ethereum ecosystem:
- from outside the blockchain
- for contract-to-contract interaction

Data is encoded according to its type

The encoding requires a schema in order to decode
Assumptions

Assumptions for contracts:
- interface functions are strongly typed, known at compilation time, static
- they'll have interface definitions of contracts they call available at compile-time

This is not for contracts with:
- dynamic interface
- only known at run-time
Function Encoding

The first 4 bytes of the call data for a function call specify the function to be called.

From the 5th byte: encoded args.

Signature: canonical expression of the basic prototype without a data location specifier

Parameter types are split by a single comma
Elementary Types 1/3

- uint<M>: unsigned integer type of 0 < M <= 256 bits.

- int<M>: two’s complement signed integer type of 0 < M <= 256 bits.

- address: equivalent to uint160, but assumed interpretation and language typing. It's used for computing the function selector.
Elementary Types 2/3

- uint, int: synonyms for uint256/int256.

- bool: uint8 restricted to the values 0 and 1.

- fixed<M>x<N>: signed fixed-point decimal number of M bits, 8 <= M <= 256, M % 8 == 0, and 0 < N <= 80.

- ufixed<M>x<N>: unsigned variant of fixed<M>x<N>.
Elementary Types 3/3

fixed, ufixed: synonyms for fixed128x18 and ufixed128x18.

bytes<M>: binary type of M bytes, 0 < M <= 32.

function: address (20 bytes) followed by a function selector (4 bytes).
FIXED-SIZE ARRAY type:

- <type>[M]: fixed-length array of M elements, M >= 0, of the given type.

NON-FIXED-SIZE types:

- bytes: dynamic byte sequence.

- string: dynamic sized Unicode string assumed to be UTF-8 encoded.

- <type>[]: variable-length array of given type elements
Tuples

Types can be combined to a tuple by enclosing them inside parentheses, separated by commas:

(T1,T2,...,Tn): tuple of the types T1, …, Tn, n >= 0

It's possible to form:
- tuples of tuples.
- arrays of tuples.
- zero-tuples (n == 0).
Mapping Solidity to ABI types

Some Solidity types are not supported by ABI, so translated to:

- address payable -> address
- contract -> address
- enum -> uint8
- user defined value types -> underlying value type
- struct -> tuple
Encoding design criteria

The encoding is designed so that:

- The number of reads necessary to access a value is at most the depth of the value inside the argument array structure

- The data of a variable/array element is not interleaved with other data and it's relocatable.
Static & Dynamic types

Static type: encoded in-place.
Dynamic type: encoded at a separate location after the current block.

Dynamic types:
- bytes
- string
- T[] for T
- T[k] for dynamic T, k >= 0
- (T1,...,Tk) if Ti is dynamic for some 1 <= i <= k

All other types are static.
if you liked this thread, follow @FrancescoCiull4 and share this one. Thank you

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Francesco Ciulla

Francesco Ciulla Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @FrancescoCiull4

16 Jan
🔲NFT Use cases thread.

NFT are not just jpegs...

12 more use cases:
🏀Sport
🎵Music
🗳️Voting
🎮 Games
🎫 Tickets
🏡 Real Estate
🚛 Supply Chain
🎨 Artwork Tracking
💡 Intellectual Property
🎓 School and Degrees
🏥 Patient's Health History
🍕 Authenticity of food/medicines

Image
🏀Sport

Highlights of some particular moments can be sold as NFTs, and they can be invaluable to a fan.

The NBA is already using this mechanism extensively.
🎵Music

Some artists have already started interacting with their fans, finding new ways to monetize using NFTs, associating them with some particular activities or unique moments.
Read 14 tweets
15 Jan
Path to Learn Docker.

One of the questions I get most often is:
"What are the steps to learn the basics of Docker?"

In this thread, I list the 10 steps that I think are optimal for a beginner.

There are no links or promotions here, just concepts.

/thread
Image
1) Understanding WHAT Docker is and what it isn't, what are the building blocks of it

2) Understanding what containerization is and why it is so important. Differences Containers/Virtual Machines

3) Install Docker on your operating system and make sure it works (`docker info`)
4) Take a look at "Docker Hub" and make a bit of practice using one image there (eg Nginx) and understand the basic commands: start/stop/list containers.

5) Understand how the components are made and their configuration: commands inspect/exec/logs.
Read 8 tweets
14 Jan
🔲Blockchain Oracles

What is a Blockchain Oracle?

In a nutshell, a bridge between the blockchain and the outside world.

in this thread, based on the Chainlink documentation, I summarize the main parts to get an idea in 5 minutes.

Table of Contents:

· definition
· decentralized oracle networks
· smart-contract problem
· oracles are bridges
· oracles + smart contracts
· critical point
· decentralized oracles
· oracle types
· oracle reputation
· reputation frameworks
· oracle use cases
· conclusion
Definition

Oracles are entities that connect blockchains to external systems.

Based on the real-world input/output, oracles enable smart contract execution.

Oracles provide a way for the Web3 ecosystem to access:
- existing data sources
- legacy systems
- advanced computations
Read 15 tweets
12 Jan
🛒NFT Marketplaces

An NFT Marketplace is a place (usually a website) that connects to your wallet.

It allows you to buy/sell NFT for different Blockchains.

Each one has its own rules/peculiarities.

Examples:
- OpenSea
- Looksrare
- Axie Infinity
- Rarible
- Decentraland

Opensea (@opensea )

Opensea is the largest NFT marketplace and the one I used to mint my first NFT.

Leader in NFT Sales and easy to use, free to sign up and support for minting.
opensea.io
Looksrare (@LooksRareNFT )

LooksRare is a community-first NFT marketplace with rewards for participating.
looksrare.org
Read 6 tweets
7 Jan
🛑BLOCKS!

No, not the Twitter ones...
the BLOCKCHAIN Blocks.

Let's quickly see some concepts related to Eth blocks:
- definition
- blocks & transactions
- block values
- block time
- block size

DEFINITION

Blocks hold batches of hashed and encoded transactions.

Each block includes the hash of the prior block, linking the two, hence forming the chain.

This iterative process confirms the integrity of the previous block, all the way back to the initial GENESIS block.
BLOCKS & TRANSACTIONS

Transactions are batched into blocks, and they are all at once:
- committed
- agreed on
- synchronized

This is to give all the participants time for consensus.
Read 7 tweets
5 Jan
⬛ETHEREUM TRANSACTIONS concepts

· definition
· transactions are for humans!
· the changed state in the EVM
· transaction information
· transaction types
· gas
· transaction lifecycle

Source: Ethereum docs.
DEFINITION

What is a transaction on the Ethereum network?

A Transaction is a cryptographically signed instruction from accounts.

An account will initiate a transaction to update the state of the Ethereum network.

A common transaction is transferring ETH from account A to B.
TRANSACTIONS ARE FOR HUMANS!

A transaction refers to an action initiated by a human who owns an externally-owned account.

Example:
Alice sends ETH to Bob
A -----> B

This causes a change of the state on the EVM (Ethereum Virtual Machine).
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(