Web3.js: Getting Error: Invalid bytes string given: 0x [[email protected]] on simple Solidity view function

Created on 19 Mar 2019  路  9Comments  路  Source: ChainSafe/web3.js

*I've looked into the other issues related to this error, but this is caused by something different

Description

Using [email protected] I have the following contract function:

pragma solidity ^0.5.2;

contract Versioned {
    string[] public data; // when deployed, data already has 1 item

    function getVersionIndex() public view returns (uint count) {
        return data.length - 1;
    }
}

The Web3 code is:

  const versionIndex = await contract.getVersionIndex();

  // ...
  public getVersionIndex(): Promise<any> {
    return this.contract.methods.getVersionIndex().call(); 
  }

Contract class already has an address and the method does not require any params.

I've tried adding the { from: "0xadress" }, but it makes no difference.

Expected behavior

Return the value of the Solidity data.length as uint count.

As a note, I've debugged the contract using https://remix.ethereum.org/ and the getVersionIndex() function works as expected.

Error Logs

The error is originating at AbiCoder.decodeParameters of web3-eth-abi.umd.js:65:

key: "decodeParameters",
      value: function decodeParameters(outputs, bytes) {

        if (!bytes || bytes === '0x' || bytes === '0X') {
          throw new Error("Invalid bytes string given: ".concat(bytes));
        }

Versions

  • web3.js: [email protected]
  • nodejs: v10.15.3
  • browser: Chrome Version 72.0.3626.121 (Official Build) (64-bit) MaxOSX
  • ethereum node: Ropsten test network with Metamask
bug

Most helpful comment

Same for me. Works fine after downgrading to [email protected]

All 9 comments

Will check this closer asap.

I'm having exactly the same issue. @nivida what clarification do you need?

I'm too facing same issue , Is there any update on this?

Same issue.

Same for me. Works fine after downgrading to [email protected]

I still get it on beta 51
Error: Uncaught (in promise): Error: Invalid bytes string given: 0x
Error: Invalid bytes string given: 0x

image

Similar issue with beta-58
Error: Invalid bytes string given: undefined

Same for me. Works fine after downgrading to [email protected]

I think downgrading and upgrading shouldn't be the solution for this problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oktapodia picture oktapodia  路  3Comments

baxy picture baxy  路  3Comments

xpepermint picture xpepermint  路  3Comments

mishell-trickster picture mishell-trickster  路  3Comments

TinyWJL picture TinyWJL  路  3Comments