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 ! :)