如何使用Crossmint API铸造NFT?

huangapple go评论72阅读模式
英文:

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 &#39;@crossmint/client-sdk-react-ui&#39;;
...
&lt;CrossmintPayButton
    clientId=&quot;...&quot;
      environment=&#39;staging&#39;
      mintConfig={{
      type: &#39;erc-721&#39;,
      totalPrice: price * quantity,
      _price: price
      _quantity: quantity,
      _tokenURI: tokenURI
    }}
/&gt;

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:"
"如果您实施此合同,您需要稍微更改按钮代码,使其类似于以下方式:"

    &lt;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 &lt; _quantity; i++) {
            uint256 tokenId = nextId.current();
            nextId.increment();

            _safeMint(_to, tokenId);

            emit Mint(tokenId);
        }
    } 

    modifier isCorrectPayment(uint256 _quantity) {
        require(msg.value == (price * _quantity), &quot;Incorrect Payment Sent&quot;);
        _;
    }

    modifier isAvailable(uint256 _quantity) {
        require(nextId.current() + _quantity &lt;= MAX_SUPPLY, &quot;Not enough tokens left for quantity&quot;);
        _;
    }

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:

    &lt;CrossmintPayButton
        clientId=&quot;_YOUR_CROSSMINT_CLIENT_ID_&quot;
        environment=&quot;staging&quot;
        mintConfig={{
            totalPrice: &quot;0.001&quot;,
            _quantity: &quot;1&quot;
    }}
    /&gt;

huangapple
  • 本文由 发表于 2023年3月7日 04:46:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655674.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定