Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to decode log data #422

Closed
jochenonline opened this issue Feb 11, 2019 · 4 comments
Closed

How to decode log data #422

jochenonline opened this issue Feb 11, 2019 · 4 comments
Labels
discussion Questions, feedback and general information.

Comments

@jochenonline
Copy link

I fetched logs via provider.getLogs. Now I try to decode the data with this:

ethers.utils.defaultAbiCoder.decode(
    [ 'string','string','bytes32','string','address' ],
    connection.data
 )

But I get

 Error: overflow (operation="setValue", fault="overflow", details="Number can only safely store up to 53 bits", version=4.0.23)

The data comes from this event:

event newConnect (
    string indexed hashedName,
    string name,
    bytes32 connectId,
    string encrypted,
    address owner
);
@ricmoo
Copy link
Member

ricmoo commented Feb 11, 2019

Keep in mind that that indexed parameters are not included in the connection.data, but in the connection.topics. You probably want something like:

ethers.utils.defaultAbiCoder.decode(
    [ 'string', 'bytes32', 'string', 'address' ],
    connection.data
 );

without the first 'string'. You can also use the Interface API to help:

let abi = [
    "event newConnect (string indexed hashedName, string name, bytes32 connectId, string encrypted, address owner)"
];

let iface = new ethers.utils.Interface(abi)

getLogs.then((logs) => {
    logs.forEach((log) => {
        console.log(iface.parseLog(log));
    });
});

That is just typed off the top of my head, so there may be typos, but that should get you started. :)

@ricmoo ricmoo added the discussion Questions, feedback and general information. label Feb 11, 2019
@jochenonline
Copy link
Author

No typos at all and both solutions work like a charm. Thank you very much!

@Perminus-Gaita
Copy link

Perminus-Gaita commented Jul 21, 2021

I have spent the last two days troubleshooting, this thread has given me the solution. I am using etherjs, I wish they had documented well that indexed parameters are not included in the connection.data, but in the connection.topics.

@zfogg
Copy link

zfogg commented Oct 22, 2022

the second solution is nice.. good thing to note is that ethers.Contract instances have Interface instances on them already, which you're likely to already be familiar with.. just call someContract.interface.parseLog(log)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Questions, feedback and general information.
Projects
None yet
Development

No branches or pull requests

4 participants