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
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
↓
🏀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.
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
↓
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.