When I tried to transfer more then 1000 tokens, it's throwing an error like as mentioned below (I'm using web3 js 1.0.0 34 beta version).

Error: [number-to-bn] while converting number 1e+23 to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported. Given value: "1e+23

Find code examples which I tried.

//var tokens = amount * 1e18;
//var tokens = amount * (10 ** 18);
//var tokens = parseInt(amount) * 1e18;
//var tokens = web3.utils.toBN(amount);
//var tokens = amount * Math.pow(10, decimal)
var tokens = web3.utils.toBN(amount * 1e18) ;

Does anyone faced this issue?

2 Answers 2


If you are using Web3.js and your token is using the standard 1018 decimal, then you can also use web3.utils.toWei() and web3.utils.fromWei() to get to and from the big numbers you want pretty easy.

In this situation you can try this:

var amount = 1000
var tokens = web3.utils.toWei(amount.toString(), 'ether')


You can then easily convert that to a BN:

var bntokens = web3.utils.toBN(tokens)
  • Thanks for the reply. when i try the above code. im getting following error. UnhandledPromiseRejectionWarning: Error: Please pass numbers as strings or BigNumber objects to avoid precision errors. code: var amount="10000000"; var token = SmartContractHelper.web3Provider.utils.toWei(parseInt(amount), 'ether'); var tokens = SmartContractHelper.web3Provider.utils.toBN(token)
    – user324534
    Sep 20, 2018 at 7:11
  • when i hardcoded the token amount, its working fine. when i pass it from the variable, its not working.. is anything am i missing?
    – user324534
    Sep 20, 2018 at 7:20
  • 1
    Check out my edit. Basically you need to use numbers represented as strings. Sep 20, 2018 at 7:23
  • I am glad it worked out. Feel free to mark this answer as correct so the question is correctly indexed as 'answered'. Sep 20, 2018 at 18:10
import { BigNumber} from 'ethers';


const decimals = 18;
const trans_amount = 1500;
const amount= BigNumber.from(trans_amount).mul(BigNumber.from(10).pow(decimals));

consoel.og("amount is ", 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.