solidityhardhat

How do pass large number to deploy in hardhat?


This is the error I get:

Error: overflow (fault="overflow", operation="BigNumber.from", value=3.96e+26, code=NUMERIC_FAULT, version=bignumber/5.5.0)
    at Logger.makeError (/home/user/www/husko.money/husko-contract/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
    at Logger.throwError (/home/user/www/husko.money/husko-contract/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
    at throwFault (/home/user/www/husko.money/husko-contract/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:358:19)
    at Function.BigNumber.from (/home/user/www/husko.money/husko-contract/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:249:17)
    at NumberCoder.encode (/home/user/www/husko.money/husko-contract/node_modules/@ethersproject/abi/src.ts/coders/number.ts:25:27)
    at /home/user/www/husko.money/husko-contract/node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19
    at Array.forEach (<anonymous>)
    at pack (/home/user/www/husko.money/husko-contract/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)
    at TupleCoder.encode (/home/user/www/husko.money/husko-contract/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20)
    at AbiCoder.encode (/home/user/www/husko.money/husko-contract/node_modules/@ethersproject/abi/src.ts/abi-coder.ts:112:15) {
  reason: 'overflow',
  code: 'NUMERIC_FAULT',
  fault: 'overflow',
  operation: 'BigNumber.from',
  value: 3.96e+26

Here is the code:

  const decimals = 18;
  const supply = 396000000 * (10**decimals);
  const fee = 50;
  const feeTaker = '0x00';
  const maxSupply = 1000000000 * (10**decimals);
  const HuskoToken = await hre.ethers.getContractFactory("HuskoToken");
  const huskoToken = await HuskoToken.deploy(supply, fee, feeTaker, maxSupply);
  await huskoToken.deployed();

Solution

  • Hardhat handles it by default with ethers this way

    const maxSupply = ethers.parseEther("1000000000")