1

I'm starting on Smart Contract and ERC721 Collectible NFT and I'm using Ethers as Provider and Metamask to connect user.

I'm working on the Mint function from a React website, and it's working good when i'm the owner (so no need to send Eth) but when I try to implement it I receive an error:

index.ts:225 Uncaught (in promise) Error: overflow (fault="overflow", operation="BigNumber.from", value=70000000000000000, code=NUMERIC_FAULT, version=bignumber/5.5.0)
    at Logger.makeError (index.ts:225)
    at Logger.throwError (index.ts:237)
    at throwFault (bignumber.ts:358)
    at Function.from (bignumber.ts:249)
    at index.ts:263
    at Generator.next (<anonymous>)
    at fulfilled (index.ts:1)

This is my smart contract mint function:

    function mint(uint256 _mintAmount) public payable {
        uint256 supply = totalSupply();

        require(!paused);
        require(_mintAmount > 0);

        if (msg.sender != owner()) {
            require(msg.value >= cost * _mintAmount);
        }
        for (uint256 i = 1; i <= _mintAmount; i++) {
            _safeMint(msg.sender, supply + i);
        }
    }

This is a working code (when I'm the owner of the contract)

await contract.mint(1);

but This one isn't working (even if i'm the owner or not)

await contract.mint(1, {value: cost});

This the documentation I tried to follow.


Metamask and Ethers as been connected using

connect(ethers.providers.Web3Provider, "any");

And the contract as been create (and signed) using:

const signer = (new ethers.providers.Web3Provider(window.ethereum)).getSigner();
const contract = new ethers.Contract(address, ABI, signer);

The cost variable is 0.07Eth (required amount to mint one NFT) and have been retrieved using the contract.cost function

const cost = parseInt((await contract.cost()).toString())


I really not understand how to fix it ? Thank you all for help ! :)

2
  • Can you post the solution to your issue please ? Mar 21, 2022 at 9:26
  • The answer under (by Kenzo Agada) resolve my question
    – Arthur
    Mar 22, 2022 at 13:41

1 Answer 1

2

The value parameter takes a string as input, so you don't need to convert the cost to an int. When you try to convert it it becomes too big to be a regular integer, and that's why you get the overflow.

So if you remove the parseInt from your cost, and just send it to mint as a string, it should work.

2
  • 1
    Ohh ! Thank you ! I tried it and it's a Javascript error and not a Ethers.js error you're right. But now I have to multiple it by the number of element to mint. How can I do it using string ? I'm tring to implement BigNumber like so const costBN = ethers.BigNumber.from(cost);
    – Arthur
    Dec 19, 2021 at 12:33
  • 1
    Making some research and I found it easly based on your answer. I'll use BigNumber.mul function
    – Arthur
    Dec 19, 2021 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.