In this track: Connect everything together
advanced · 6 MIN READ

Decode a dynamic string call

Follow the tuple-relative pointer before reading UTF-8 content.

LET’S PICTURE IT

An index entry points to an attachment with its own length.

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.

Use the exact declaration

Decode setMessage(string) with the supplied interface. The first four bytes frame the function request and are not part of the argument tuple’s offset base.

Read the dynamic head

The first argument word contains 32. Add that offset to argument byte zero, which begins immediately after the selector.

Read the tail boundaries

The next word contains length five, then the bytes of hello and twenty-seven padding bytes. Length counts payload bytes, not padding.

Check absolute positions

The string length begins at calldata byte 36 and content at byte 68. Re-encode the recovered value and compare complete calldata.

Your acceptance target

function setMessage(string message)
arguments: ["hello"]

selector: 0x368b8772
arguments begin at calldata byte 4

word 0 · argument offset 0 bytes
0x0000000000000000000000000000000000000000000000000000000000000020

word 1 · argument offset 32 bytes
0x0000000000000000000000000000000000000000000000000000000000000005

word 2 · argument offset 64 bytes
0x68656c6c6f000000000000000000000000000000000000000000000000000000

Use only local examples and public sample addresses. State the assumptions and limits alongside the result.

TURN UNDERSTANDING INTO PRACTICEOpen the Calldata decoder →
QUICK CHECK · NO PRESSURE

Where does the string content begin in this example?

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.