import { EventLog, Hash } from 'tevm';const TRANSFER_SIG = Hash('0xddf252ad...');// Match Transfer events with any from/to addressesconst matches = log.matchesTopics([ TRANSFER_SIG, // topic0 must be Transfer signature null, // topic1 can be any address null, // topic2 can be any address]);
Specific hash must match exactly at that position:
import { EventLog, Hash } from 'tevm';const TRANSFER_SIG = Hash('0xddf252ad...');const userHash = Hash('0x000000000000000000000000a1b2c3d4...');// Match Transfer events TO specific userconst matches = log.matchesTopics([ TRANSFER_SIG, // Exact signature null, // from: any userHash, // to: specific user]);
Matches if log topic equals ANY hash in the array:
import { EventLog, Hash } from 'tevm';const TRANSFER_SIG = Hash('0xddf252ad...');const APPROVAL_SIG = Hash('0x8c5be1e5...');// Match Transfer OR Approval eventsconst matches = log.matchesTopics([ [TRANSFER_SIG, APPROVAL_SIG], // topic0 can be either]);
import { EventLog, Hash } from 'tevm';const TRANSFER_SIG = Hash('0xddf252ad...');// Addresses in the groupconst groupHashes = [ Hash('0x000...addr1'), Hash('0x000...addr2'), Hash('0x000...addr3'),];// Transfers between any group membersconst intraGroupTransfers = allLogs.filter(log => log.matchesTopics([ TRANSFER_SIG, groupHashes, // from: any group member groupHashes, // to: any group member ]));console.log(`Intra-group transfers: ${intraGroupTransfers.length}`);
import { EventLog } from 'tevm';// Anonymous events: topic0 is first indexed param, not signatureconst anonymousLog = EventLog({ address: contractAddress, topics: [param1Hash, param2Hash, param3Hash], data: Bytes(),});// Match by first indexed parameter (NOT signature)const matches = anonymousLog.matchesTopics([ param1Hash, // topic0 is first param null, // topic1 is second param (any) param3Hash, // topic2 is third param]);