1
 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?

1 Answer 1

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))

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.