Beginner

Events & Logs — Key concepts

Understand how contracts emit data to the chain.

Developer Beginner
3/7 — Events & Logs — Key concepts

Indexed vs non-indexedIndexed parameters go into topics (up to 3 + the event signature); non-indexed go into the data blob. Choose indexed for fields you want to filter by (e.g., from, to, id).

Event signatureThe first topic is keccak256("EventName(type1,type2,...)"). Changing names or types changes the signature and breaks consumers.

Log orderingLogs are emitted in the order you write emit statements within a transaction. They’re attached to the receipt once the tx is mined; reorgs can roll them back until confirmed.

Cost vs storageEvents are far cheaper than storage writes but aren’t readable on-chain. If you need on-chain logic to see data later, store it; if you need history for UIs/analytics, emit it.

event Transfer(address indexed from, address indexed to, uint256 value);

function send(address to, uint256 value) external {
    // ...state updates...
    emit Transfer(msg.sender, to, value);
}

Boom filtersFrontends often subscribe to Transfer(from?, to?) filters. If you change indexed params or stop emitting, dashboards break. Treat events as part of your public contract.

← Previous section
Next section →