In this track: ABI encoding foundations
advanced · 4 MIN READ

Encode uint256 step by step

An unsigned integer occupies one left-padded 32-byte word.

LET’S PICTURE IT

A numbered box can be right-aligned in a fixed-width shelf with empty leading spaces.

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.

Check the range

uint256 represents integers from zero through 2²⁵⁶ − 1. A negative or out-of-range input does not become valid merely by adding zeros.

Convert the integer to hex

Decimal 42 is hexadecimal 2a. Standard ABI uint256 encoding places those bits at the lower-order end of a thirty-two-byte word.

Pad on the left

Fill the remaining leading bytes with zeros until the word has sixty-four hexadecimal digits. The 0x prefix is display notation and is not an extra encoded byte.

Keep economic scale separate

This word could represent Wei, raw token units or a counter. The uint256 schema explains numeric representation, while the application supplies the quantity’s meaning.

Follow the bytes

types: uint256
values: ["42"]
no function selector prefix

word 0 · argument offset 0 bytes
0x000000000000000000000000000000000000000000000000000000000000002a

The final byte is 0x2a; preceding bytes are zero.

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

Where are zeros added when encoding the small uint256 value 42?

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.