In this track: Build, test and reason
advanced · 4 MIN READ

Property-based ABI round trips

Encoding and decoding should agree under the exact schema.

LET’S PICTURE IT

A form printed and read back should retain the original typed fields.

SEE IT FOR YOURSELF
Build a transfer call from typed fieldsStep 1 / 4
Build a transfer call from typed fieldstransfer(address,uint256)Recipient: 0x0000…0001Raw amount: 100Diagram labels abbreviate addresses; the lab shows full bytes4-byte selectora9059cbbEach box is one byte; this prefix is not a 32-byte wordWord 0 · recipient address12 zero bytes20 address bytes000…0001Left padding preserves the lower-order address valueSelector4 bytesa9059cbbAddress32 bytesword 0Amount32 bytesword 1 → 0x644 + 32 + 32 = 68 bytesThe integer does not contain token decimals or market price

The standard transfer interface takes an address and a raw integer amount. This diagram uses address one and amount one hundred.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Generate values inside the type range

An int8 fixture must remain within its signed range; a bytes4 fixture needs exactly four bytes. Invalid values should be tested under rejection properties instead.

Keep the schema fixed and explicit

Encode the generated values with known types and decode with those same types. Raw bytes do not carry the complete ABI schema themselves.

Compare values losslessly

Normalize harmless representation differences without converting large integers through unsafe floating-point numbers. Preserve byte sequence lengths.

Add independent byte fixtures

One library’s encoder and decoder can share a mistake. Known expected words and another implementation provide additional evidence beyond a round trip.

Define the test

typed values → encode → bytes → decode → typed values
assert equality
then compare selected fixtures with independently calculated words

Test plans are framework-neutral unless labeled as complete Solidity or JavaScript. Use a local test environment and no real funds.

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

Can a same-library round trip miss a shared encoder/decoder error?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

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