使用OpenSea指南的代码铸造过程中的错误

发布于 2025-01-18 12:53:43 字数 1324 浏览 0 评论 0原文

我正在尝试按照 Opensea指南。一切都很好,直到我为令牌设定价格并添加了付款关键字。现在,当我尝试铸造时,我会得到错误事务值不等于薄荷价格。查看我认为我需要以msg.value以某种方式发送ETH的代码,但我不确定语法是什么?

这是我在Shell中的铸造方式:

npx hardhat mint --address {wallet_address}

这是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}`);
});

.SOL合同中的Mintto功能:

 // 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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后来的我们 2025-01-25 12:53:43

我想出了这个问题的解决方案。您需要在 mint.js 中的 mint 任务内设置价格,如下所示:

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}`);
});

我还没有找到一种方法来从合约中导入 MINT_PRICE 变量。注意:您可能需要在文件顶部添加 const { ethers } = require("ethers");

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文