truffle-box / react-box

Truffle, Webpack and React boilerplate.
https://truffle-box.github.io/
MIT License
736 stars 251 forks source link

Issue when using web3.eth.fromWei #21

Closed davekaj closed 5 years ago

davekaj commented 7 years ago

I keep getting this weird bug where I am calling web3.eth.fromWei:

getOneTimecontribution() { singleContract.setProvider(this.state.web3.currentProvider) var contractInstance;

this.state.web3.eth.getAccounts((error, accounts) => {
  singleContract.at(this.props.chosenContract).then((instance) => {
    contractInstance = instance;
    return contractInstance.getOneTimecontribution.call();
  }).then((result) => {
    console.log(result);
    let getOneTime = this.state.web3.eth.fromWei(result, "ether");
    console.log(getOneTime);
  })
})

}

And then I get an error that is the following:

Uncaught (in promise) TypeError: _this10.state.web3.eth.fromWei is not a function

I think this is a truffle box issue because I am using the same code in a js test script and it works properly.

Mizumaki commented 5 years ago

In web3 v1.0, you should call fromWei through utils.

let getOneTime = this.state.web3.eth.utils.fromWei(result, "ether");

https://web3js.readthedocs.io/en/1.0/web3-utils.html#fromwei

adrianmcli commented 5 years ago

That's correct, thanks @Mizumaki!