3

I am trying to read events from a contract already deployed on the blockchain. The event might return uint which is has the indexed property.

First I was using web3 from metamask and worked normally, but I want to use infura now, independently if the user has metamask or not. So I created the websocket but when I try to read I get this error: Error: Returned values aren't valid, did it run Out of Gas.

Searching on the web some people say is because the returned value from the event has the property indexed, I could change the contract, but do not feel like I should.

Has anyone else came across this type of error?

I am using vue... The way I am calling the event is:

getADN() {
  let ADNCreated = this.$store.state.contractADN().getPastEvents('allEvents', {
      fromBlock:0,
      toBlock: 'latest'
  }, function(error, events){ console.log("error:", error); }).then(function(events){
    console.log(events) // same results as the optional callback above
  });

As you can see there is nothing much special about it.

2

1 Answer 1

1

This was a bug in that specific version of web3.js (web3.js@1.0.0-beta.36). [1]
Consider the following complete example, based on the original code snippet:

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

const contractAddress = "0x . . .";
const contractAbi = [ . . . ];
var contract = new web3.eth.Contract(contractAbi, contractAddress);

contract.getPastEvents("allEvents", {
    fromBlock:0,
    toBlock: "latest"
}, function(error, events){ console.log("error:", error); }).then(function(events){
    console.log(events)
}); 

Executing node events.js using web3@1.0.0-beta.36 package returns:

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

It has been fixed in the package release after beta 36: web3@1.0.0-beta.37 [2].
Repeating the node events.js command, with that newer web3 beta version, against a valid deployed contract address containing a set of events, is expected to work.

Example output structure:

error: null
[ { address: '0x...',
    blockHash: '0x...',
    blockNumber: ...,
    logIndex: ...,
    removed: false,
    transactionHash: '0x...',
    transactionIndex: ...,
    id: '...',
    returnValues: 
     Result {
     },
    event: '...',
    signature: '0x...',
    raw: { data: '0x', topics: [...] } } ]

[1] https://github.com/ethereum/web3.js/issues/1916
[2] https://github.com/ethereum/web3.js/releases/tag/1.0.0-beta.37

Stay super!

Javi

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.