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

Build a function selector calculator

Derive the first four digest bytes from a canonical signature.

LET’S PICTURE IT

A short action label is calculated from an agreed full action description.

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.

Normalize the signature

Use function name and canonical input types with no names or spaces. For the transfer example, use transfer(address,uint256).

Hash as UTF-8 text

Calculate Keccak-256 of the signature bytes. Finalized SHA3-256 is a different algorithm and cannot be substituted here.

Take the prefix correctly

The first four bytes are eight hex digits after 0x. Do not take four digits or the final four bytes.

Verify and state limits

The transfer fixture should produce 0xa9059cbb. A selector is short and can collide, so it is not a globally unique authenticated function identity.

Your acceptance target

signature: transfer(address,uint256)
expected selector: 0xa9059cbb

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

TURN UNDERSTANDING INTO PRACTICEOpen the Keccak-256 →
QUICK CHECK · NO PRESSURE

How many hex digits after 0x make a four-byte selector?

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.