-1

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.

multi422
  • 61
  • 1
  • 10

1 Answers1

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.

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"
    }}
    />
dmulvi
  • 639
  • 5
  • 6
  • Thank you for your reply. I have already deployed contract with the following https://github.com/dmulvi/evm-721-starter. But I don't know how to change metadata and price of NFT. Is there any method to realize minting using only ? If there isn't, how can I change metadata and price of NFT? Thanks. Could you tell me your email or skype name? Please, help me – multi422 Mar 07 '23 at 10:24
  • Hey @OliverPyon, that contract has two methods that you can call to achieve what you're after. They are named `setPrice` and `setURI`. The easiest way to interact with a deployed contract is via the block explorer such as https://goerli.etherscan.io/. Go there and enter your contract address. If you've verified/published the source code you can can interact with it. The best way to get more direct followup support is in our public discord. Join us there and create a post in the support forum. https://discord.gg/crossmint – dmulvi Mar 07 '23 at 23:13
  • Thanks for your help. So you mean, cant I realize minting NFTs using only Crossmint? Do I have to interact with a deployed contract using web3? – multi422 Mar 08 '23 at 17:04
  • @OliverPyon - if you want to be able to call contract methods besides your mint function then, yes. You'll need to use another tool to make those updates. These are typically protected functions on the contract that can only be called by the wallet which deployed the contract or another that's been granted the privilege. – dmulvi Mar 09 '23 at 14:35