英文:
How to mint NFTs using Crossmint API?
问题
我正在开发一个整合Crossmint API的NFT市场。我已经像下面这样在我的网站上添加了crossmintPayButton。
import { CrossmintPayButton } from '@crossmint/client-sdk-react-ui';
...
<CrossmintPayButton
clientId="..."
environment='staging'
mintConfig={{
type: 'erc-721',
totalPrice: price * quantity,
_price: price,
_quantity: quantity,
_tokenURI: tokenURI
}}
/>
请问如何编写合同的铸造(mint)函数来铸造NFT?请帮助我。
英文:
I am developing NFT marketplace integrating Crossmint API now.
I added crossmintPayButton to my website like the following.
import { CrossmintPayButton } from '@crossmint/client-sdk-react-ui';
...
<CrossmintPayButton
clientId="..."
environment='staging'
mintConfig={{
type: 'erc-721',
totalPrice: price * quantity,
_price: price
_quantity: quantity,
_tokenURI: tokenURI
}}
/>
How can I write mint function of contract to mint NFTs?
Please, help me.
答案1
得分: 0
以下是翻译好的部分:
"So the answer to this question is a bit involved, but I'll give you the high level. You'll want to inherit from OpenZeppelin contracts most likely to help minimize the potential mistakes."
"对于这个问题的答案有点复杂,但我会为您提供高层次的解释。您很可能需要继承自OpenZeppelin合同,以帮助减少潜在的错误。"
"Here is an example mint function that will work with Crossmint:"
"这里是一个与Crossmint一起使用的示例铸币函数:"
function mint(address _to, uint256 _quantity)
external
payable
isCorrectPayment(_quantity)
isAvailable(_quantity)
{
mintInternal(_to, _quantity);
}
function mintInternal(address _to, uint256 _quantity) internal {
for (uint256 i = 0; i < _quantity; i++) {
uint256 tokenId = nextId.current();
nextId.increment();
_safeMint(_to, tokenId);
emit Mint(tokenId);
}
}
modifier isCorrectPayment(uint256 _quantity) {
require(msg.value == (price * _quantity), "Incorrect Payment Sent");
_;
}
modifier isAvailable(uint256 _quantity) {
require(nextId.current() + _quantity <= MAX_SUPPLY, "Not enough tokens left for quantity");
_;
}
"这是一个可以与Crossmint一起使用的示例铸币功能:"
"All of this code is taken from a sample starter NFT contract you can check out here: https://github.com/dmulvi/evm-721-starter"
"所有这些代码都来自一个样本起始NFT合同,您可以在此处查看:https://github.com/dmulvi/evm-721-starter"
"If you implement this contract you'll need to change your button code slightly to look like this:"
"如果您实施此合同,您需要稍微更改按钮代码,使其类似于以下方式:"
<CrossmintPayButton
clientId="YOUR_CROSSMINT_CLIENT_ID"
environment="staging"
mintConfig={{
totalPrice: "0.001",
_quantity: "1"
}}
/>
"如果您实施此合同,您需要稍微更改您的按钮代码,使其看起来像这样:"
英文:
So the answer to this question is a bit involved, but I'll give you the high level. You'll want to inherit from OpenZeppelin contracts most likely to help minimize the potential mistakes.
Here is an example mint function that will work with Crossmint:
function mint(address _to, uint256 _quantity)
external
payable
isCorrectPayment(_quantity)
isAvailable(_quantity)
{
mintInternal(_to, _quantity);
}
function mintInternal(address _to, uint256 _quantity) internal {
for (uint256 i = 0; i < _quantity; i++) {
uint256 tokenId = nextId.current();
nextId.increment();
_safeMint(_to, tokenId);
emit Mint(tokenId);
}
}
modifier isCorrectPayment(uint256 _quantity) {
require(msg.value == (price * _quantity), "Incorrect Payment Sent");
_;
}
modifier isAvailable(uint256 _quantity) {
require(nextId.current() + _quantity <= MAX_SUPPLY, "Not enough tokens left for quantity");
_;
}
All of this code is taken from a sample starter NFT contract you can check out here: https://github.com/dmulvi/evm-721-starter
If you implement this contract you'll need to change your button code slightly to look like this:
<CrossmintPayButton
clientId="_YOUR_CROSSMINT_CLIENT_ID_"
environment="staging"
mintConfig={{
totalPrice: "0.001",
_quantity: "1"
}}
/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论