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: 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)
Could you please add the complete example?
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.
Will test and if required fix it asap.
Reproduced this same issue on 1.0.0-beta.50, working on 1.0.0-beta.39
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
This got fixed with https://github.com/ethereum/web3.js/commit/2ce2412daea89c3fa90fa2f589617e514602ac40 and will be released today.
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.
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!
@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
The correct if is:
if (data && data !== '0x') {
....
}
0x0 should be handled as 0 or false.
@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
Most helpful comment
This got fixed with https://github.com/ethereum/web3.js/commit/2ce2412daea89c3fa90fa2f589617e514602ac40 and will be released today.