Error: Please pass numbers as strings or BN objects to avoid precision errors

Viewed 511
<tbody>
    <tr style={{color: 'white'}}>
        <td>{window.web3.utils.fromWei(this.props.stakingBalance, 'ether')} USDT</td>
        <td>{window.web3.utils.fromWei(this.props.rwdBalance, 'ether')} RWD</td>                       
    </tr>
</tbody>

Error: Please pass numbers as strings or BN objects to avoid precision errors. not able to display the stakingBalance and rwdBalance, it asks to pass as strings or BN objects

1 Answers

As the error says "Please pass numbers as strings"

<td>{window.web3.utils.fromWei(String(this.props.stakingBalance), 'ether')} USDT</td>
 <td>{window.web3.utils.fromWei(String(this.props.rwdBalance), 'ether')} RWD</td>      

If you are getting this balances via await web3.eth.getBalance() function, this function already returns "string". If so, the problem is somewhere in your code, you might have this function:

  web3.utils.toWei("passStringValueHere", "ether")

  
Related