web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

getPastEvents failing to decode empty data

Open andrewheadricke opened this issue 8 years ago • 68 comments

I'm trying out web3 v1.0.0-beta.36 and having some trouble with pulling events from a contract.

The events do not return any data, and getPastEvents is throwing this error:

Error: Returned values aren't valid, did it run Out of Gas?

The same action works in web3 0.20.7 no problem.

Is it possible a bug in decoding of empty event data 0x may have slipped through the cracks?

andrewheadricke avatar Sep 04 '18 11:09 andrewheadricke

Probably same issue here.

Error: Returned values aren't valid, did it run Out of Gas?

TestCode:

contract = new web3.eth.Contract(abi,address);    

contract.events.TestEvent(()=>{
}).on('data', function(event){
 console.log(event);
}).on('error', function(error){
 console.log(error);
});

Did work in beta.35 throws error in beta.26 althougt not in the error handler.

Boehrner avatar Sep 05 '18 10:09 Boehrner

Same problem on web3 beta.35 and beta.36

goodstemy avatar Sep 05 '18 11:09 goodstemy

I'm running into the same issue with 1.0.0-beta.36 and MetaMask provider.

Edit: Error occurs in web3-eth-abi index.js:226. The bytes parameter has a value of 0x and outputs === [].

As a workaround I uncommented that error throwing line. I can't see any negative side effects so far. The event is accessable and my DAPP works as intended. It's just that weirdo in between.

Here's an example transaction causing web3 to break: https://rinkeby.etherscan.io/tx/0x2f943ce121c47624fc00b7829bf5d8cae26c1fe97365c250063d7da6d9a1f6df

The according solidity event: event Release(uint256 indexed id, address indexed owner); Provisioned values: (8, msg.sender)

pstuermlinger avatar Sep 05 '18 12:09 pstuermlinger

Probably same issue here.

Error: Returned values aren't valid, did it run Out of Gas?

TestCode:

contract = new web3.eth.Contract(abi,address);    

contract.events.TestEvent(()=>{
}).on('data', function(event){
 console.log(event);
}).on('error', function(error){
 console.log(error);
});

Did work in beta.35 throws error in beta.26 althougt not in the error handler.

have u solved it yet? I have met the same problem

lutianzhou001 avatar Sep 13 '18 16:09 lutianzhou001

The comment previous to yours mentions how to fix it.

andrewheadricke avatar Sep 13 '18 23:09 andrewheadricke

Got the same issue. the version of web3: 1.0.0-beta.33; the detail code:

const Web3 = require("web3");

let web3 = new Web3(
  new Web3.providers.WebsocketProvider("wss://rinkeby.infura.io/ws")
);

const ABI = [...];
const addrC = '0x...';
const testC = new web3.eth.Contract(ABI,addrC);

testC.getPastEvents("Log", { fromBlock: 0, toBlock: "latest" }, function(
  error,
  events
) {
  if (error) {
    console.log(error);
  } else {
    console.log(events);
  }
});

the output:

Error: Returned values aren't valid, did it run Out of Gas?
    at ABICoder.decodeParameters (C:\Users\userName\Desktop\web3-1\node_modules\web3-eth-abi\src\index.js:226:15)
    at ABICoder.decodeLog (C:\Users\userName\Desktop\web3-1\node_modules\web3-eth-abi\src\index.js:283:52)
    at Object.Contract._decodeEventABI (C:\Users\userName\Desktop\web3-1\node_modules\web3-eth-contract\src\index.js:377:31)
    at C:\Users\userName\Desktop\web3-1\node_modules\web3-core-method\src\index.js:160:57
    at Array.map (<anonymous>)
    at Method.formatOutput (C:\Users\userName\Desktop\web3-1\node_modules\web3-core-method\src\index.js:159:23)
    at sendTxCallback (C:\Users\userName\Desktop\web3-1\node_modules\web3-core-method\src\index.js:473:33)
    at Object.<anonymous> (C:\Users\userName\Desktop\web3-1\node_modules\web3-core-requestmanager\src\index.js:147:9)
    at C:\Users\userName\Desktop\web3-1\node_modules\web3-providers-ws\src\index.js:121:44
    at Array.forEach (<anonymous>)
    at W3CWebSocket.WebsocketProvider.connection.onmessage (C:\Users\userName\Desktop\web3-1\node_modules\web3-providers-ws\src\index.js:98:36)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\userName\Desktop\web3-1\node_modules\yaeti\lib\EventTarget.js:107:17)
    at W3CWebSocket.onMessage (C:\Users\userName\Desktop\web3-1\node_modules\websocket\lib\W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (C:\Users\userName\Desktop\web3-1\node_modules\websocket\lib\W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (events.js:182:13)
    at WebSocketConnection.processFrame (C:\Users\userName\Desktop\web3-1\node_modules\websocket\lib\WebSocketConnection.js:552:26)
    at C:\Users\userName\Desktop\web3-1\node_modules\websocket\lib\WebSocketConnection.js:321:40
    at process._tickCallback (internal/process/next_tick.js:61:11)

ghost avatar Sep 15 '18 07:09 ghost

Same problem on beta.36

12548 avatar Sep 17 '18 06:09 12548

It looks like given error:

Error: Returned values aren't valid, did it run Out of Gas?

only occures when event definition which You want to read/download using getPastEvents method has every parameter field marked as indexed.

Transfer event definition from ERC-721:

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

Use getPastEvents to read Transfer events will fail due to such error. This also means that You custom events build in Your contracts will also fails.

I tested events with mixed fields (2 x indexed, 2 x not indexed) and it works fine for me. Seems like we have to wait for patch or propose one.

exogenesick avatar Sep 19 '18 13:09 exogenesick

This seems to be an issue many are hitting including myself. Just attempting to go back through the versions to try and see where this may have started.

Can confirm this was introduced in v1.0.0-beta.36 in my case, specifying v1.0.0-beta.35 exactly and re-running brings up events as expected rather than the "Error: Returned values aren't valid, did it run Out of Gas?".

AC0DEM0NK3Y avatar Sep 27 '18 22:09 AC0DEM0NK3Y

[email protected] works fine

nezzard avatar Sep 28 '18 16:09 nezzard

Same issue. Downgrading to beta 35 worked for as well.

csmartinsfct avatar Sep 28 '18 19:09 csmartinsfct

Thanks for submitting this issue I will fix that in the next build.

nivida avatar Sep 28 '18 19:09 nivida

The issue isn't specific to handling empty data, it fails for me when data is supposed to be returned as well. Just to make that clear :)

csmartinsfct avatar Sep 28 '18 19:09 csmartinsfct

same issue

yvonnezhangxyz avatar Sep 28 '18 20:09 yvonnezhangxyz

I get the same issue using web3.eth.ens.getMultihash on the version 36 and 35. Any advice? I can confirm that there would be nothing returned (as previously 'web3.eth.ens.setMultihash' was never set on this ENS address. Thanks.

moskalyk avatar Oct 04 '18 00:10 moskalyk

Added simple project that demonstrates this issue. It happens also when the event has only indexed values - hence no data.

https://github.com/yarrumretep/web3_1916

My fix:

patch-package
--- a/node_modules/web3-eth-abi/src/index.js
+++ b/node_modules/web3-eth-abi/src/index.js
@@ -280,7 +280,7 @@ ABICoder.prototype.decodeLog = function (inputs, data, topics) {
 
 
     var nonIndexedData = data;
-    var notIndexedParams = (nonIndexedData) ? this.decodeParameters(notIndexedInputs, nonIndexedData) : [];
+    var notIndexedParams = (nonIndexedData && nonIndexedData !== '0x') ? this.decodeParameters(notIndexedInputs, nonIndexedData) : [];
 
     var returnValue = new Result();
     returnValue.__length__ = 0;

yarrumretep avatar Oct 05 '18 15:10 yarrumretep

Any ETA for the next build?

AleG94 avatar Oct 06 '18 08:10 AleG94

I got the same error. The weird things is all worked fine, untill suddenly it gave me that error. Downgrading to 1.0.0-beta.35 gives me this error: Couldn't decode uint256 from ABI: 0x

@yarrumretep how do we implement your fix? I changed the proposed data in the index.js file. The errror is still there.

Update: I think this error has to do with MetaMask. I was running some tests and it turns out I don't have the error when I run my browser in private mode. Then when I removed MetaMask, all worked fine again. Hope this helps @nivida .

Deelux avatar Oct 07 '18 14:10 Deelux

1.0.0-beta.35 also solves it for me. Fix this.

masterial avatar Oct 08 '18 18:10 masterial

1.0.0-beta.35 also solves it for me. Fix this.

Bump

0xdantrinh avatar Oct 08 '18 18:10 0xdantrinh