7

I get the following error when passing (new BigNumber('2')).exponentiatedBy(100) big number value as uint256

Error: invalid BigNumber string value (arg="value", value="1.267650600228229401496703205376e+30", version=4.0.28)

I am using Truffle, but seems like a web3 issue? I'm not sure. Anyone seen this before. Wouldn't a valid uint256 go up to 2^255 ?

1 Answer 1

4

I'm not sure what BigNumber version you have installed as part of your project.

But Truffle exposes a global Web3 instance called web3, which exposes big-number functionality.

Therefore:

  • If you're using Truffle v4.x, then you may as well do web3.toBigNumber(2).pow(100).
  • If you're using Truffle v5.x, then you may as well do web3.utils.toBN(2).pow(100).
2
  • BN of web3 doesnt deal with decimals
    – Kombo
    Feb 11, 2021 at 6:54
  • Getting this error: An unexpected error occurred: TypeError: num.bitLength is not a function at toBitArray (/home/pam/our-contracts/node_modules/number-to-bn/node_modules/bn.js/lib/bn.js:628:27) at BN.pow (/home/pam/our-contracts/node_modules/number-to-bn/node_modules/bn.js/lib/bn.js:1931:13) at test2 (/home/pam/our-contracts/tasks/2.js:16:36) at process._tickCallback (internal/process/next_tick.js:68:7) error Command failed with exit code 1.
    – Anupam
    Mar 22, 2021 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.