'Convert BN to number

In truffle console I am executing the following statement,

result = token.balanceOf(accounts[1])

This statement returns the following output.

<BN: 8ac7230489e80000>

As suggested here, I am trying to use toNumber() and toString. But I am getting the following error.

result = token.balanceOf(accounts[1])
result.toString()
output: '[object Promise]'
result.toNumber()
TypeError: result.toNumber is not a function

Help me to fix this thiis.



Solution 1:[1]

like @Saddy mentioned you can do await for the promise to resolve as shown by @Ofir or do then as shown below.

truffle(development)> await instance.getBalance(accounts[0]).then(b => { return b.toNumber() })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jimson James