5

I am using this code below and I got an error:

await web3.eth.getTransactionReceipt(this.state.transactionHash, (err, txReceipt)=>{
          console.log(err,txReceipt);
          this.setState({txReceipt})
        }); //await for getTransactionReceipt

        await this.setState({transactionHash: this.state.txReceipt.transactionHash});
        await this.setState({blockNumber: this.state.txReceipt.blockNumber});
        await this.setState({gasUsed: this.state.txReceipt.gasUsed});    

The error is:

MetaMask - RPC Error: invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash

Can you please tell me how to solve this error?

5
  • Which version of web3 are you using? What is the value of transactionHash?
    – Ismael
    Mar 18, 2020 at 22:53
  • I am using [email protected] and the value of transaction hash is '0x29c680fb90517d2611eb8856b8ce6f645574a9dad77584c21b76a052a2d6e1d8'
    – Ahmed
    Mar 19, 2020 at 5:19
  • I'd suggest trying different versions of web3, like 1.2.5, 1.2.4 or similar. And create an issue for web3 developers with a reproducible case.
    – Ismael
    Mar 19, 2020 at 12:55
  • @Ismael I have tried 1.2.4 and 1.2.5 versions , still give me same error.
    – Ahmed
    Mar 21, 2020 at 5:41
  • Sorry but I'm not able to test because the hash doesn't exist in a public blockchain. Similar error happened to me and it was a bug inside web3, so it doesn't have a workaround. Create a reproducible test and report as an issue or debug it and report your findings
    – Ismael
    Mar 21, 2020 at 21:33

1 Answer 1

2

I may probably be late to this thread but I think this may be useful for others. I also encountered a similar issue that lead me to this thread in search of answers.

In my case, I was attempting to get the account balance of an ethereum account like so:

provider.request({
          method: "eth_getBalance",
          params: [wallet.address], "latest"],
        });

But I actually passed a wrong value (wallet.address - This value was null) in the first index of the params property which resulted in the error.

The correct snippet is shown below:

provider.request({
          method: "eth_getBalance",
          params: [wallet.accounts[0], "latest"],
        });

Hence, for subsequent devs who encounter such issues, this may simply be due to a wrong value being provided.

1
  • Thanks for sharing this. This was my exact case!!! Mar 26, 2022 at 23:08

Your Answer

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

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