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

TypeError thrown when event received. #15

Open
kybernetikos opened this issue Apr 8, 2018 · 7 comments
Open

TypeError thrown when event received. #15

kybernetikos opened this issue Apr 8, 2018 · 7 comments

Comments

@kybernetikos
Copy link

kybernetikos commented Apr 8, 2018

TypeError thrown when event received.

Running in nodejs, I watch for the following event:

    event Transfer(address indexed _from, address indexed _to, uint256 _value);

When the event occurs, an exception is thrown:

Error: [ethjs-filter] while decoding filter change event data from RPC '[{"logIndex":"0","transactionIndex":"0","transactionHash":"0x6b0d1c8f2b072615aab822459b6318bfad01dca4663c2c4d41c6cdd1d84b3033","blockHash":"0x1f603b873f6e016ce99a2f4a34b13e877cbdd94308e4fc4fbd42f1d8a132cb1a","blockNumber":"17","address":"0x345ca3e014aaf5dca488057592ee47305d9b3e10","data":"0x0000000000000000000000000000000000000000000000001bc16d674ec80000","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000627306090abab3a6e1400e9345bc60c78a8bef57","0x000000000000000000000000f17f52151ebef6c7334fad080c5704d77216b732"],"type":"mined"}]': TypeError: Cannot read property 'slice' of undefined
    at C:\Development\sandbox\ethereum\repl-alliance\node_modules\ethjs-filter\lib\index.js:29:31
    at C:\Development\sandbox\ethereum\repl-alliance\node_modules\ethjs-query\lib\index.js:101:16
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)

The problem appears to be caused in the decodeEvent function. My topics array contains only a single value - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. This was set by eth-contract v0.1.9 and is the hash of the signature of the Transfer event. However, the code in decodeEvent looks for a value in topics[1].

The event has two indexed 'inputs' and is not anonymous, but there is only a single item in the topics array (the signature), so the .slice is called on undefined, and the exception is thrown.

@SilentCicero
Copy link
Member

SilentCicero commented Apr 8, 2018 via email

@kybernetikos
Copy link
Author

do you have a fix in the meantime?

That depends a little. I don't have enough background in the code to be confident with suggesting a fix at the moment.

I look at decodeEvent, and I see that it separates indexed values from nonindexed values. I don't really understand why it needs to read some values from the topics (the indexed values) and some values from the data (the nonindexed values). Is it because data doesn't include indexed values?

If data doesn't include indexed values, and they're not in the topics array either, then I'm not sure where they can be read from. Or does data sometimes include indexed values and not other times? In which case, we could check to see if the values are in topics and use them from there, and if not, try to read them from data.

@SilentCicero
Copy link
Member

SilentCicero commented Apr 9, 2018 via email

@kybernetikos
Copy link
Author

kybernetikos commented Apr 9, 2018

I've been running against ganache and ganache-cli.

(which incidentally shows another problem - the first 16 watchers for the node don't seem to work properly - I think the watcher ids are being set without a leading 0 which ganache expects, or something like that)

My smart contract is https://github.com/ConsenSys/Tokens/blob/master/contracts/eip20/EIP20.sol and my listen code is

            // e.g. event = EIP20.Transfer
            const filter = event({ delay:10000 });

            filter.new({
                "fromBlock": "latest",
                "toBlock": "latest"
            }).then((filterId) => {
                console.log('\nFilter id ' + filterId + ' created.');
                filter.watch((err, result) => {
                    if (err) {
                        console.log('\nEvent error:', err);
                    } else {
                        console.log('\nEvent:', name + '.' + evtName, result);
                    }
                });
            });

@SilentCicero
Copy link
Member

SilentCicero commented Apr 9, 2018 via email

@coinsandsteeldev
Copy link

its gone

@olivier-nerot
Copy link

olivier-nerot commented Nov 14, 2018

I'm faced to the same error. Trying to understand it, to make my project work.

In ethjs-contract (https://github.com/ethjs/ethjs-contract/blob/master/dist/ethjs-contract.js)
On line 7398, we have
return abi.decodeEvent(methodObject, logData, filterTopcis);
With filterTopcis defined on line 7388

      var filterTopic = '0x' + keccak256(methodObject.name + '(' + filterInputTypes.join(',') + ')');
      var filterTopcis = [filterTopic];

So abi.decodeEvent is called with a filterTopcis with a single element.

But in eth-abi (https://github.com/ethjs/ethjs-abi/blob/master/src/index.js), on line 147 :
const topic = new Buffer(topics[i + topicOffset].slice(2), 'hex');
with
const topicOffset = eventObject.anonymous ? 0 : 1;

So the decodeEvent may look for topics[1] if the event is not anonymous, which leads to the error seen. I still wonder how this could be solved...

(by the way, may be filterTopcis should be modified to filterTopics in ethjs-contract.js...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants