question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error "no matching event" while parsing logs

See original GitHub issue

Hi while parsing an Log array I’m getting the following error:

no matching event (argument="topichash", value="0x0109fc6f55cf40689f02fbaad7af7fe7bbac8a3d2186600afc7d3e10cac60271", code=INVALID_ARGUMENT, version=abi/5.0.10)

I’m sure I’m missing something. On a different event and a different contract everything works like a charm.

This is my code:

let abi: string[] = [
    "event RoundDetailsUpdated(uint128 indexed paymentAmount, uint32 indexed minSubmissionCount, uint32 indexed 
    maxSubmissionCount, uint32 restartDelay, uint32 timeout)",
    ];
let iface: utils.Interface = new utils.Interface(abi);
const filter: providers.Filter = {
address: "0x2f6BfbBB5d9CD374574Aa552dC6942C01D330C75",
fromBlock: 11630000,
    };
const logs: providers.Log[] = await this.infuraProvider.getLogs(filter);
let events: utils.LogDescription[] = logs.map((log) => iface.parseLog(log));
console.log(events);

I know there were some similar issues with parsing but I couldn’t solve my issue with that solutions. Also those issues were more specific e.g. https://github.com/ethers-io/ethers.js/issues/1077.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
kangzeroocommented, Feb 3, 2022

For anyone still getting this issue, the below may work for you.

import ethers from "ethers";
const abi = [     
    "event Transfer(address indexed from, address indexed to, uint256 value)",
    "event Approval(address indexed owner, address indexed spender, uint256 value)",
    // any other event you want to recognize
];
const iface = new ethers.utils.Interface(abi);
const decodedLogs = transaction.logs.map(log => {
    try {
      return iface.decodeEventLog("Transfer", log.data, log.topics)
    } catch (e) {
      return
    }
});
console.log(decodedLogs)

and the decodedLogs will look like this:

[
  [
    '0x0000000000000000000000000000000000000000',
    '0xcEba60280fb0ecd9A5A26A1552B90944770a4a0e',
    BigNumber { _hex: '0x6f058a6b9c39d456', _isBigNumber: true },
    from: '0x0000000000000000000000000000000000000000',
    to: '0xcEba60280fb0ecd9A5A26A1552B90944770a4a0e',
    value: BigNumber { _hex: '0x6f058a6b9c39d456', _isBigNumber: true }
  ],
  ...,
  undefined
]

You can verify that this event data is correct by searching the transactionHash on etherscan and comparing the event log data there, versus decodedLogs.

I was stuck on this for a while because of that undefined that sneaks in. I’m not sure why its there, but the try catch handles it gracefully enough.

Kudos to @linumlabs for their well written article on iface.decodeEventLog and @tangrisjones who helped debug this with try catch.

3reactions
ricmoocommented, Jan 12, 2021

A few ideas. 😃

Idea 1) If you aren’t trying to use the primitives for a good reason, you can use the higher level Contract API:

(async function() {
    // Use Contract instead of Interface (internally it creates `contact.interface`)...
    const contract = new ethers.Contract("0x2f6BfbBB5d9CD374574Aa552dC6942C01D330C75", abi, infuraProvider);
    // ...and now you can use it to create the filter for you, which will
    // reduce bandwidth as it only fetches the desired (matching) events
    const filter = contract.filters.RoundDetailsUpdated();
    // And the query filter will automatically parse any logs it understands
    const events = await contract.queryFilter(filter, 11244882);
    console.log(events);
})();

Idea 2) If you need to use the primitives because of upstream dependencies, or you already have the primitives left over from somewhere else:

const iface = new utils.Interface(abi);
const filter = {
    address: "0x2f6BfbBB5d9CD374574Aa552dC6942C01D330C75",
    // Filtering by the event topic directly saves bandwidth and only
    // returns matching logs
    topics: [ iface.getEventTopic("RoundDetailsUpdated") ],
    fromBlock: 11244882
};

(async function() {
    const logs = await infuraProvider.getLogs(filter);
    let events = logs.map((log) => iface.parseLog(log));
    console.log(events);
})();

Note: @azat-s the library you linked to looks like it just uses Web3, which just uses ethers anyways, so you are likely just adding extra dependencies that ultimately just wrap things in try…catch. 😃

Let me know if that helps, or it there are other constraints you are aiming to satisfy. There is likely an easy (ish) way to get what you want. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ethers contract on method "No mathing event" error
Ethers contract.on() (docs) is invoked when an event with the specified name is emitted. Your snippet is passing a function name ...
Read more >
Parsing log data - New Relic Documentation
Troubleshooting. If parsing isn't working the way you intended, it may be due to: Logic: The parsing rule matching logic doesn't match the...
Read more >
Uknown error while parsing user agent data - Elastic Discuss
I'm trying to parse some iis logs and i'm seeing this error in my logstash ... IllegalStateException: No match found, :field=>"useragent", ...
Read more >
LOG SOURCE EXTENSIONS MIGHT FAIL TO PARSE ... - IBM
DSMExtensionException: An error occurred when trying to process match group: Log Source Extension for full W3C fields [ecs-ec] [Event Parser[0]] at ...
Read more >
Documentation - Ethers.js
When a Contract creates a log, it can include up to 4 pieces of data to be ... If there is no avatar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found