What is ABI Encoding? #90
-
What is ABI encoding and what data in the Ethereum world is commonly ABI encoded? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
What is ABI encoding?ABI encoding is a specification for turning structured data into bytes. Structured data can be: static (eg int,uint,bool, etc,...), dynamic (eg bytes, string), arrays, and tuples. Arrays can be fixed length (ie int[4]) or dynamic length (ie int[]). Static means the size of the data is known by the type. Fixed length arrays and tuples are can be static if all of their members are static. ABI decoding requires a schema since the encoded data doesn't include any information about what has been encoded. Here is an example of decoding with a schema: abi.Decode(b, schema.Parse("(uint8, uint8[])")) In this example, we are decoding the bytes in The official spec for ABI encoding is extremely thorough and recommended for a precise understanding: https://docs.soliditylang.org/en/v0.8.19/abi-spec.html What is ABI encoded?There are 2 common scenarios in which you will encounter ABI encoded data:
Transaction input dataThe data contains: a 4 byte function identifier followed by ABI encoded bytes. It is not uncommon for projects to append bytes after the abi encoded data for things like attribution. You can find transaction input data on the Etherscan transaction page by clicking: show more The first 4 bytes are: These 4 bytes are created by:
The remaining 448 bytes (14 32-byte words) are the ABI encoded argument inputs:
The following schema:
Event logsLogs are emitted during the execution of a transaction and have cryptographic commitments via receipt_root in the block header. Each log contains an address ( You can find a log on the Etherscan transaction page by clicking: logs Address: The first topic:
Is created by:
The remaining inputs are ABI encoded in the Data field:
The following schema:
|
Beta Was this translation helpful? Give feedback.
What is ABI encoding?
ABI encoding is a specification for turning structured data into bytes. Structured data can be: static (eg int,uint,bool, etc,...), dynamic (eg bytes, string), arrays, and tuples. Arrays can be fixed length (ie int[4]) or dynamic length (ie int[]). Static means the size of the data is known by the type. Fixed length arrays and tuples are can be static if all of their members are static.
ABI decoding requires a schema since the encoded data doesn't include any information about what has been encoded. Here is an example of decoding with a schema:
In this example, we are decoding the bytes in
b
as a single tuple containing…