An offset is useful only when you know its starting point.
LET’S PICTURE IT
A direction saying walk sixty-four steps needs a clearly marked starting line.
SEE IT FOR YOURSELF
Follow a dynamic string from head to tailStep 1 / 4
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.
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.At argument byte 32, the string tail begins with length five. This counts the UTF-8 payload bytes and excludes all padding.At argument byte 64, read 68 65 6c 6c 6f for hello. Twenty-seven following zero bytes fill the final content word.The encoding uses ninety-six argument bytes: one offset word, one length word and one padded content word. A normal function call adds a four-byte selector before these bytes.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Identify the containing tuple
At the top level, offsets are relative to the start of the encoded argument tuple. The beginning of a complete transaction input is a different location when a selector is present.
Convert the display correctly
An offset of hexadecimal 40 means decimal 64 bytes. It does not mean forty bytes, forty words or sixty-four hexadecimal characters. Every byte occupies two hex digits.
Calculate the absolute position
A top-level string offset of 64 points to calldata byte 68 when four selector bytes precede the arguments. The stored offset itself remains 64.
Repeat the reasoning when nested
A nested tuple has its own local base. Label that base before adding the nested offset, rather than measuring every pointer from the outermost transaction input.
Trace a local example
types: bool,string
values: [true,"go"]
no function selector prefix
word 0 · argument offset 0 bytes
0x0000000000000000000000000000000000000000000000000000000000000001
word 1 · argument offset 32 bytes
0x0000000000000000000000000000000000000000000000000000000000000040
word 2 · argument offset 64 bytes
0x0000000000000000000000000000000000000000000000000000000000000002
word 3 · argument offset 96 bytes
0x676f000000000000000000000000000000000000000000000000000000000000