0

I am using Truffle v5.5.5 and solidity 0.8.0.

I have the following constructor in my contract:

contract rNFT is ERC721Enumerable, Ownable {
  using Strings for uint256;

  string baseURI;
  string public baseExtension = ".json";
  uint256 public cost; // = 0.0 ether;
  uint256 public maxSupply = 999999999999999999;
  uint256 public maxMintAmount = 1;
  bool public paused = false;
  bool public revealed = true;
  string public notRevealedUri;

  constructor(
    string memory _name,
    string memory _symbol,
    string memory _initBaseURI,
    string memory _initNotRevealedUri,
    uint256 _cost
  ) ERC721(_name, _symbol) {
    setBaseURI(_initBaseURI);
    setNotRevealedURI(_initNotRevealedUri);
    setCost(_cost);
  }

So basically the costs can also be set for the contract.

When deploying with truffle I use the following:

var rNFT = artifacts.require("../contracts/rNFT.sol");

module.exports = function(deployer) {
  deployer.deploy(rNFT, "rNFT", "rNFT", "www._initBaseURI.com", "www._initNotRevealedUri.com", 0.12);

};

However, I get the following error:


Error:  *** Deployment Failed ***

"rNFT" -- underflow (fault="underflow", operation="BigNumber.from", value=0.12, code=NUMERIC_FAULT, version=bignumber/5.0.8).

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:379:1
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:68:1)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:54:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:202:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:152:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:117:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:94:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:78:1)
    at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:44:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)
UnhandledRejections detected
Promise {
  <rejected> Error: underflow (fault="underflow", operation="BigNumber.from", value=0.12, code=NUMERIC_FAULT, version=bignumber/5.0.8)
      at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:348:1
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:68:1)
      at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:54:1)
      at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:202:1)
      at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:152:1)
      at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:117:1)
      at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:94:1)
      at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:78:1)
      at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:44:1)
      at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1) {
    reason: 'underflow',
    code: 'NUMERIC_FAULT',
    fault: 'underflow',
    operation: 'BigNumber.from',
    value: 0.12,
    hijackedStack: 'Error: underflow (fault="underflow", operation="BigNumber.from", value=0.12, code=NUMERIC_FAULT, version=bignumber/5.0.8)\n' +
      '    at lib_esm_Logger.makeError (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/node_modules/@ethersproject/logger/lib.esm/index.js:166:1)\n' +
      '    at lib_esm_Logger.throwError (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/node_modules/@ethersproject/logger/lib.esm/index.js:175:1)\n' +
      '    at throwFault (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js:273:18)\n' +
      '    at Function.from (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js:175:1)\n' +
      '    at NumberCoder.encode (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/lib.esm/coders/number.js:13:17)\n' +
      '    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/lib.esm/coders/array.js:57:1\n' +
      '    at Array.forEach (<anonymous>)\n' +
      '    at pack (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/lib.esm/coders/array.js:43:1)\n' +
      '    at TupleCoder.encode (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js:19:16)\n' +
      '    at AbiCoder.encode (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/@ethersproject/abi/lib.esm/abi-coder.js:82:1)\n' +
      '    at ABICoder.encodeParameters (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/lib/index.js:120:1)\n' +
      '    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:438:1\n' +
      '    at Array.map (<anonymous>)\n' +
      '    at Object._encodeMethodABI (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:437:6)\n' +
      '    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/contract/lib/execute.js:275:1\n' +
      '    at processTicksAndRejections (node:internal/process/task_queues:96:5)'

Any suggestions what I am doing wrong? I just want to set the costs for each NFT in the contract.

I appreciate your replies!

2
  • Solidity doesn't support decimal numbers. Use full integers Commented Mar 21, 2022 at 19:17
  • @LauriPeltonen I tried using ` deployer.deploy(rNFT, "rNFT", "rNFT", "www._initBaseURI.com", "www._initNotRevealedUri.com", 120000000000000000); ` however I get the following error again "rNFT" -- overflow (fault="overflow", operation="BigNumber.from", value=120000000000000000, code=NUMERIC_FAULT, version=bignumber/5.0.8).
    – Carol.Kar
    Commented Mar 21, 2022 at 21:55

1 Answer 1

1
deployer.deploy(
    rNFT,
    "rNFT",
    "rNFT",
    "www._initBaseURI.com",
    "www._initNotRevealedUri.com",
    **0.12**
);

you can’t have 0.12, there is no float on EVM

If by 0.12 you meant 0.12 ETH, it should be instead 120000000000000000 (18decimals).

There is a nice wei to ether converter here

3
  • 1
    Just a precision, the error is actually coming from Ethers.js, it's not an arithmetic underflow per say (it never reached the EVM), just Ethers.js implementation that forbids non integer BigNumber values as can be seen here (github.com/ethers-io/ethers.js/blob/…) , ethers.BigNumber.from(2.0) is perfectly valid for example.
    – hroussille
    Commented Mar 21, 2022 at 20:00
  • If I use the wei format I still get the error: "rNFT" -- overflow (fault="overflow", operation="BigNumber.from", value=120000000000000000, code=NUMERIC_FAULT, version=bignumber/5.0.8).
    – Carol.Kar
    Commented Mar 21, 2022 at 21:54
  • it should be a string or BN
    – Adam Boudj
    Commented Mar 21, 2022 at 22:07

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.