web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.23k stars 4.93k forks source link

getPastEvents Error Empty outputs array given! #2582

Closed patitonar closed 5 years ago

patitonar commented 5 years ago

Description

I got this error when getting the events in the following code

await contract.getPastEvents('ValidatorAdded', {fromBlock: 0});

The abi of the event:

    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "name": "validator",
          "type": "address"
        }
      ],
      "name": "ValidatorAdded",
      "type": "event"
    }

Error Logs

Error: Empty outputs array given!
    at AbiCoder.decodeParameters (web3-eth-abi.umd.js:59)
    at AbiCoder.decodeLog (web3-eth-abi.umd.js:121)
    at EventLogDecoder.decode (web3-eth-contract.umd.js:228)
    at web3-eth-contract.umd.js:775
    at Array.map (<anonymous>)
    at PastEventLogsMethod.afterExecution (web3-eth-contract.umd.js:774)
    at PastEventLogsMethod._callee$ (web3-core-method.umd.js:99)
    at tryCatch (runtime.js:62)
    at Generator.invoke [as _invoke] (runtime.js:288)
    at Generator.prototype.(:3000/anonymous function) [as next] (http://localhost:3000/static/js/bundle.js:1382:21)
    at asyncGeneratorStep (asyncToGenerator.js:3)
    at _next (asyncToGenerator.js:25)

Versions

nivida commented 5 years ago

Could you please add the complete example?

patitonar commented 5 years ago

Created a simple example on this repo https://github.com/patitonar/test-web3-getPastEvents On master branch using version 1.0.0-beta.50 is failing. On working-example branch using version 1.0.0-beta.47 is working without errors.

nivida commented 5 years ago

Will test and if required fix it asap.

dileepfrog commented 5 years ago

Reproduced this same issue on 1.0.0-beta.50, working on 1.0.0-beta.39

jamesmorgan commented 5 years ago

I have also just seen this when updating web3js, previous version 1.0.0-beta-37 - also can confirm this worked as expected on 1.0.0-beta.47

nivida commented 5 years ago

This got fixed with https://github.com/ethereum/web3.js/commit/2ce2412daea89c3fa90fa2f589617e514602ac40 and will be released today.

Anaphase commented 5 years ago

I seem to be getting this same error when calling myContract.methods.myMethod(...).send() for a method that has no return value. It appears the transaction does get sent but the .then() never fires and this error is thrown.

I could be missing something though, I'm currently knee deep in upgrading from 1.0.0-beta.34 to 1.0.0-beta.52, which has been a challenge to say the least.

hqblock commented 5 years ago

I was having the same error after upgrading to 1.0.0-beta52 and using web3.eth.abi.decodeLog. The error message shows when the receipt's data field is '0x', and this value is passed to decodeLog for the data argument. When I set the data value to null it works fine.

May I suggest updating web3.eth.abi.decodeLog the same way it was done for EventLogDecoder ? https://github.com/ethereum/web3.js/blob/2ce2412daea89c3fa90fa2f589617e514602ac40/packages/web3-eth-contract/src/decoders/EventLogDecoder.js#L50-L52

Thanks!

Anaphase commented 5 years ago

@hqblock, good catch! When I update web3.eth.abi.decodeLog with the same change on line 232, I can actually submit my transaction now:

if (data && data !== '0x' && data !== '0x0') { ... }

Note that, in my specific use case, checking for 0x0 was also necessary. ~I still can't get logs for a contract using web3.eth.contract.getPastEvents (I just get an empty list?) and I think that may also be related to log decoding somehow... still digging around.~

UPDATE: the getPastEvents() error I mentioned was unrelated and caused by my own stupidity. However, I'm pretty sure updating web3.eth.abi.decodeLog as @hqblock suggested is a good idea! ~I'll try to put together a PR.~ See #2686

nivida commented 5 years ago

The correct if is:

if (data && data !== '0x') {
....
}

0x0 should be handled as 0 or false.

Anaphase commented 5 years ago

@nivida Okay, I figured out what my issue was with decodeLog - it's something different than just the "empty data" check. I will create a separate issue since adding to the comments of this closed issue seems inappropriate.

See: #2695