my erc20 smart contract has:

uint256 public _totalSupply = 1_000_000 * (10 ** _decimals);

Im trying to test dapp and in App.js file this code:

// fetching balance of Testtoken and storing in state
let testTokenBalance = await testToken.methods
.balanceOf(accounts[0])
.call();
let convertedBalance = window.web3.utils.fromWei(
testTokenBalance.toString(),
'Ether'
);
setUserBalance(convertedBalance);

But when testing Dapp and connecting my wallet dapp shows my token balance as 0.001000000

I know it has something to do with "fromwei" converting, but how to change this code to actually have real value displayed?

Feb 1, 2023, 10:52 PM
here you do 18 decimals
use "gwei" instead of "ether"
Feb 1, 2023, 11:02 PM
wooo it works, thank you bro
Feb 1, 2023, 11:04 PM

© 2024 Draquery.com All rights reserved.