Try it Live
Run ABI examples in the interactive playground
Usage Examples
Parse All Contract Events
Filter Specific Event Type
See Also
- Event.decodeLog - Decode single log with event definition
- getItem - Find specific event in ABI
Parse multiple event logs using full ABI
import * as Abi from 'tevm/Abi'
const abi = [...] // Full ERC20 ABI
const logs = await provider.getLogs({
address: tokenAddress,
fromBlock: startBlock,
toBlock: endBlock
})
const decoded = Abi.parseLogs(abi, logs)
// Process decoded events
for (const log of decoded) {
if (log.eventName === "Transfer") {
console.log(`Transfer: ${log.args.value} from ${log.args.from} to ${log.args.to}`)
} else if (log.eventName === "Approval") {
console.log(`Approval: ${log.args.value} from ${log.args.owner} to ${log.args.spender}`)
}
}
import * as Abi from 'tevm/Abi'
const abi = [...]
const logs = await provider.getLogs({ address: contractAddress })
const decoded = Abi.parseLogs(abi, logs)
// Get only Transfer events
const transfers = decoded.filter(log => log.eventName === "Transfer")
for (const transfer of transfers) {
console.log(transfer.args)
}
Was this page helpful?