0

I am trying to execute commands from the following tutorial:

medium Dev Tutorial

I am getting an integer error while executing a command:

truffle(ganache)> balanceInEth = address => web3.utils.fromWei(getBalance(address).toString(), 'wei')

[Function: balanceInEth]

truffle(ganache)> balanceInEth(victim.address)

/usr/local/lib/node_modules/truffle/build/cli.bundled.js:57187 throw new Error('[number-to-bn] while converting number ' + JSON.stringify(arg) + ' to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.');

Somebody please guide me.

Zulfi.

1 Answer 1

1

Looking at the medium article you've referred, it looks like the balanceInEth function is just a reference to web3.eth.getBalance. The function returns a Promise which resolves into a string.

getBalance(address).toString() would convert the Promise into a string and not the result returned by the Promise. You can use async-await to wait for the promise to complete.

balanceInEth = async(address) => web3.utils.fromWei(await getBalance(address))

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.