Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Error: Invalid bytes string given: 0x [web3@1.0.0-beta.48] on simple Solidity view function #2527

Closed
netpoe opened this issue Mar 19, 2019 · 9 comments · Fixed by #2608
Labels
Bug Addressing a bug

Comments

@netpoe
Copy link

netpoe commented Mar 19, 2019

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

Description

Using web3@1.0.0-beta.48 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: web3@1.0.0-beta.48
  • nodejs: v10.15.3
  • browser: Chrome Version 72.0.3626.121 (Official Build) (64-bit) MaxOSX
  • ethereum node: Ropsten test network with Metamask
@nivida nivida added the Needs Clarification Requires additional input label Mar 19, 2019
@nivida
Copy link
Contributor

nivida commented Mar 19, 2019

Will check this closer asap.

@koderholic
Copy link

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

@Karandeep-singh-saini
Copy link

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

@tgreco
Copy link

tgreco commented Mar 26, 2019

Same issue.

@rajeshsubhankar
Copy link

Same for me. Works fine after downgrading to web3@1.0.0-beta.27

@nivida nivida added Bug Addressing a bug and removed Needs Clarification Requires additional input labels Mar 29, 2019
@HoangJerry
Copy link

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

@HoangJerry
Copy link

image

@nivida nivida mentioned this issue Apr 4, 2019
12 tasks
@jbtobar
Copy link

jbtobar commented Jun 28, 2019

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

@sumitpatel93
Copy link

Same for me. Works fine after downgrading to web3@1.0.0-beta.27

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants