In this track: Dynamic ABI and nested layouts
advanced · 5 MIN READ

Encode a uint256 array

Dynamic arrays begin their tail with an element count.

LET’S PICTURE IT

A list first announces how many numbered entries the reader should expect.

SEE IT FOR YOURSELF
Follow a dynamic string from head to tailStep 1 / 4
Follow a dynamic string from head to tailArgument headbyte 0 · offset 32hex word ends in 20String tailstarts at byte 32length + contentPositions are measured from argument byte zero, excluding any selectorOffset destinationargument byte 32read a length wordLength = 5hello is five UTF-8 bytescontent starts at byte 64A length word and an offset word have different jobsContent word · argument byte 6468 65 6c 6c 6f5 payload bytes27 padding bytesBlocks are schematic; their drawn widths do not represent the exact byte ratioHeadoffset: 32argument byte 0Tail lengthlength: 5argument byte 32Tail contenthello + paddingargument byte 6432 + 32 + 32 = 96 bytesWith a four-byte selector, total calldata length is 100 bytes

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.

Keep the top-level pointer

A uint256[] argument is dynamic. Its head word points to its array encoding, even though each individual integer element has a static encoding.

Write the number of elements

For values 7 and 9, the array length word contains two. This is an element count, not the number of bytes used by the elements.

Place static elements directly

The two integer words follow the length in order. There is no per-element offset because uint256 values are static and each occupies one full word.

Check total encoded length

One outer offset word, one array length word and two element words make 128 bytes. A fixed uint256[2] type would use a different layout without the dynamic length prefix.

Trace a local example

types: uint256[]
values: [["7","9"]]
no function selector prefix

word 0 · argument offset 0 bytes
0x0000000000000000000000000000000000000000000000000000000000000020

word 1 · argument offset 32 bytes
0x0000000000000000000000000000000000000000000000000000000000000002

word 2 · argument offset 64 bytes
0x0000000000000000000000000000000000000000000000000000000000000007

word 3 · argument offset 96 bytes
0x0000000000000000000000000000000000000000000000000000000000000009

Words: outer offset 32, count 2, value 7, value 9.

TURN UNDERSTANDING INTO PRACTICEOpen the ABI encoder →
QUICK CHECK · NO PRESSURE

What does the array length word count?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.