使用OpenSea指南的代码铸造过程中的错误
我正在尝试按照 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了这个问题的解决方案。您需要在 mint.js 中的 mint 任务内设置价格,如下所示:
我还没有找到一种方法来从合约中导入 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:
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.