0

I'm trying to deploy my first SmartContract following the Opensea guide. Everything was working fine until I set a price for my tokens and added the payable keyword. Now when I try to mint, I get the error Transaction value did not equal the mint price. Looking at the code I'm thinking I need to send ETH in the mint request in msg.value somehow but I'm not sure what the syntax would be for that?

Here's how I'm minting in shell:

npx hardhat mint --address {wallet_address}

Here's the mint function in JS:

task("mint", "Mints from the NFT contract")
.addParam("address", "The address to receive a token")
.setAction(async function (taskArguments, hre) {
const contract = await getContract("NFT", hre);
const transactionResponse = await contract.mintTo(taskArguments.address, {
    gasLimit: 500_000,
});
console.log(`Transaction Hash: ${transactionResponse.hash}`);
});

And the mintTo function in the .sol contract:

 // Main minting function
 function mintTo(address recipient) public payable returns (uint256) {
    uint256 tokenId = currentTokenId.current();
    require(tokenId < TOTAL_SUPPLY, "Max supply reached");
    require(msg.value == MINT_PRICE, "Transaction value did not equal the mint price");

    currentTokenId.increment();
    uint256 newItemId = currentTokenId.current();
    _safeMint(recipient, newItemId);
    return newItemId;
}
DarkBee
  • 16,592
  • 6
  • 46
  • 58
cronoklee
  • 6,482
  • 9
  • 52
  • 80
  • Related question: Am I expected to mint every token in my collection before deploying to opensea? It seems like that could be quite expensive – cronoklee Apr 03 '22 at 19:45

1 Answers1

0

I figured out a solution for this issue. You need to set the price inside the mint task in mint.js like so:

task("mint", "Mints from the NFT contract")
.addParam("address", "The address to receive a token")
.setAction(async function (taskArguments, hre) {
    const contract = await getContract("NFT", hre);
    const transactionResponse = await contract.mintTo(taskArguments.address, {
        gasLimit: 500_000,
        value: ethers.utils.parseEther("0.01")
    });
    console.log(`Transaction Hash: ${transactionResponse.hash}`);
});

I have not figured out a way to have this import the MINT_PRICE variable from the contract. Note: You may need to add const { ethers } = require("ethers"); at the top of the file.

cronoklee
  • 6,482
  • 9
  • 52
  • 80
  • I found this answer in one of the pull requests in github: https://github.com/ProjectOpenSea/nft-tutorial. Hope it helps someone else! – cronoklee Apr 11 '22 at 09:42