In this track: Dynamic ABI and nested layouts
Nested dynamic array walkthrough
Each dynamic array layer has a count and its own element region.
A list of lists needs directions to each inner list and a count for each one.
This example encodes one string parameter with value hello. A dynamic argument uses an offset in its head, even when it is the only argument.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Start with the outer array
For uint256[][] holding [1,2] and [3], the top-level head points to an outer length of two. Its two elements are themselves dynamic arrays.
Read outer element pointers
The outer element tuple begins after the outer count. Its two pointer words contain 64 and 160: the first inner array consumes ninety-six bytes.
Read each inner list
At the first destination, length two is followed by integer words 1 and 2. At the second destination, length one is followed by the integer word 3.
Keep counts and offsets distinct
An inner length is a number of elements, while a pointer is a number of bytes from a local base. Identical-looking integer words can have very different structural roles.
Trace a local example
types: uint256[][]
values: [[["1","2"],["3"]]]
no function selector prefix
word 0 · argument offset 0 bytes
0x0000000000000000000000000000000000000000000000000000000000000020
word 1 · argument offset 32 bytes
0x0000000000000000000000000000000000000000000000000000000000000002
word 2 · argument offset 64 bytes
0x0000000000000000000000000000000000000000000000000000000000000040
word 3 · argument offset 96 bytes
0x00000000000000000000000000000000000000000000000000000000000000a0
word 4 · argument offset 128 bytes
0x0000000000000000000000000000000000000000000000000000000000000002
word 5 · argument offset 160 bytes
0x0000000000000000000000000000000000000000000000000000000000000001
word 6 · argument offset 192 bytes
0x0000000000000000000000000000000000000000000000000000000000000002
word 7 · argument offset 224 bytes
0x0000000000000000000000000000000000000000000000000000000000000001
word 8 · argument offset 256 bytes
0x0000000000000000000000000000000000000000000000000000000000000003The outer element pointers are 64 and 160.
Why is the second inner offset 160?
The first inner array contains its count and two value words.
Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.