Skip to content

Testing emits

Course: Ganache, Trufle, Hardhat and Foundry - chapter 10

Ref - https://book.getfoundry.sh/forge/cheatcodes

The ERC-20 contract emits events whenever a transfer/approval happens.

Ref - ‣

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol#L249

In Solidity, emits refers to the action of emitting an event. Events are a fundamental feature of the Ethereum smart contract system, allowing contracts to log important data that can be observed externally.

// Declaring an event
event Transfer(address indexed from, address indexed to, uint256 value);
// Emitting an event
emit Transfer(msg.sender, recipient, 100);

This is how they’re stored on the blockchain

Section titled “This is how they’re stored on the blockchain”
Event Log:
- Topics:
- from: 0x1234567890abcdef (address of the sender)
- to: 0xfedcba0987654321 (address of the recipient)
- Data:
- value: 1000 (value transferred in the transaction)
Indexed Parameters in Events

https://etherscan.io/tx/0x046c2609f21f3308d8f7f902a51ac14f86b9e6b9f54ab1b4f269575d09bc93e5#eventlog

In Solidity, events allow you to mark some of the parameters as indexed. Indexed parameters make the event log searchable, as they allow external listeners (like DApps or off-chain services) to filter events by those parameters more efficiently.

The EVM allows you to index up to 3 parameters per event.

$1b