0

I am trying to mint a nft token from my test using a tokenId number like this: 123456789123456789123456 a very big number, but when I try to mint I get the following error:

{ Error: overflow (fault="overflow", operation="BigNumber.from", value=1.0341003020512021e+23, code=NUMERIC_FAULT, version=bignumber/5.0.8)

but I do not suppose that uint256 is a number like 115792089237316195423570985008687907853269984665640564039457

here is the test

it('should allow to mint a new nft', async () => {
    await MyInstance
      .mintMyNFT([103410030205120203030613], {
        from: accounts[1],
        value: 60000000000000001,
      })
      .catch((error) => {
        console.log(error);
      });

    const NFTOwner = await MyInstance.ownerOf(
      103410030205120203030613
    );
    assert.equal(NFTOwner, accounts[1]);
  });

How can I solve this problem?

1 Answer 1

1

JavaScript can natively only deal with integers of size 2^53 - 1. So to deal with the big numbers in Solidity, you can use the BigNumber library. Assuming you're using truffle's test suite, that would look something like

const { BigNumber } = require("@ethersproject/bignumber");

it('should allow to mint a new nft', async () => {
    const NFTIndex = BigNumber.from('103410030205120203030613');
    await MyInstance
      .mintMyNFT([NFTIndex], {
        from: accounts[1],
        value: 60000000000000001,
      })
      .catch((error) => {
        console.log(error);
      });

    const NFTOwner = await MyInstance.ownerOf(
      NFTIndex
    );
    assert.equal(NFTOwner, accounts[1]);
  });

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.