ganache test returns characters instead of numbers

by bbusdriver   Last Updated August 14, 2019 01:28 AM - source

 mapping(uint256 => uint256) public amount;

 function saveAmount(uint256 _id, uint256 _amount) public {
    amount[_id] = _amount;
 }

I have a function that saves amount in mapping. When I test this using ganache, I get a weird character values. For example,

instance.saveAmount(1, 100000, {from: account[1]})

then, to see the amount,

instance.amount(1) which yields

BN: 186a0

Why is it not showing 100000?



Answers 1


The call is returning the hex value as a big number.

0x186a0 in hex is 100000 in decimal.

It is a big number because it is easier to deal with ETH values in that format.

To get the number representation from the call, you should do the following:

var amount = instance.amount(1)
console.log(Number(amount))
shane
shane
August 13, 2019 23:30 PM

Related Questions


Error: Cannot create instance of X; no code at address

Updated February 20, 2019 12:28 PM

Truffle and Ganache-cli test case fails

Updated December 21, 2018 06:28 AM