How to write big numbers into a migrations script?

Hi abcoathup

Cant understand how write in 2_deploy_contracts.js rate and cap

    const rate = new web3.BigNumber(2*10^-18);
    const cap = 200 * 100000;
TypeError: web3.BigNumber is not a constructor
1 Like

Hi @asven-2020,

I just use strings '1000000000000000000000'.

Though happy to hear better ways to do this using a big number or some other syntax.

If you use the version of the web3 is 1.0, you can use web3.utils.toBN() in the web3,


and also you can use web3.utils.toWei(1234, 'ether') => 1234000000000000000000
But I would like to use bn.js or bignumber.js.

1 Like

thank you

also want ask mul in JS give mistake as i see it is function safeMath also I see mul in crowdsale test it give TypeError: rate.mul is not a function

1 Like

Hi @asven-2020,

If you want to do arithmetic in your JavaScript tests, you will need to use a BigNumber library.

OpenZeppelin Test Helpers include a bn.js object:

Does that answer your question?