Bring your own contract

How to use the Mint API with your existing Smart Contract in Polygon.

When you use the standalone Minting API, Crossmint takes care of deploying a smart contract on your behalf for every collection. This Crossmint contract may not meet all of your custom needs. In those cases, you can bring your own contract and have the Minting API mint from it on your behalf. It can also handle gas fee payments, scalability, reliability and user wallet creation for you.

📘

Bringing your contract is currently under private alpha

If you'd like access, please reach out to support to let us know about your use case.

Smart contract pre-requisites

The Crossmint Minting API imposes the following requirements on your smart contract:

  • It must implement the ERC721 standard
  • It must have a non-payable mint function for free claims
  • Such function must allow the Crossmint treasury account to mint off of it. Refer to the table below for the appropriate address depending on whether you're in mainnet or devnet.
ChainAddress
Polygon Devnet (Mumbai)0xDa30ee0788276c093e686780C25f6C9431027234
Polygon Mainnet0x12A80DAEaf8E7D646c4adfc4B107A2f1414E2002

We recommend that you use Open Zeppelin's audited AccessControl contract to manage the authorization logic. Here is a very basic abbreviated example of how to implement this:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/access/AccessControl.sol";

...

contract BYOCMinter is ERC721, AccessControl {

    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

    constructor() payable ERC721("EVM 721 Starter", "XMPL") {
        _grantRole(MINTER_ROLE, msg.sender);

        // THIS IS THE IMPORTANT DETAIL
        _grantRole(MINTER_ROLE, '0xDa30ee0788276c093e686780C25f6C9431027234'); // polygon mumbai
        _grantRole(MINTER_ROLE, '0x12A80DAEaf8E7D646c4adfc4B107A2f1414E2002'); // polygon mainnet
    }

    function mint(address _to, string calldata uri) external onlyRole(MINTER_ROLE) {
        // mint function logic
    } 
}

Integration Guide

1️⃣ Create a Crossmint developer account and set up your project

To get started, the first thing you'll need to do is register as a developer in the Crossmint developer console.

Crossmint has two consoles: one for production, at www.crossmint.com/console, and one for testing and development, at staging.crossmint.com/console.

Once your account is created and logged into the developer console, you can navigate to the API Keys tab and create a key with the nfts.mint scope.

2️⃣ Register your smart contract

While on the Crossmint developer console, navigate to the Payments tab, click on New Collection, and fill in the form. The description, image and logo are not relevant here, so you can leave them blank. For blockchain, enter Polygon.

Once created, click on Contract Registration, and enter the following info about your smart contract:

  • Contract type: ERC-721
  • Contract address: the address of your deployed smart contract
  • ABI section for mint function: copy the ABI for your contract obtained on compilation or by successful contract verification on Polygonscan
  • NFT recipient address mint function argument
  • NFT amount mint function argument: leave as “N/A
1600

contract registration example via developer console

3️⃣ Contract review

Copy the client ID from the collection page in the Crossmint console:

842

client id location example via developer console

Then provide your Crossmint team point of contact with such client ID.

We will provide you with a collection ID that can be used with the minting API to mint from your contract.

4️⃣ Start minting NFT's!

You can call any of the Mint API functions documented in our API reference.

The only difference is that the Mint an NFT function request changes: you can’t pass custom metadata (as that’s controlled by your contract), and you must all pass all the parameters needed to call your mint function, except the one specifying the recipient (which is populated by our application). All in all, the request body looks as follows:

{
  "recipient": "<locator in format specified at https://docs.crossmint.com/docs/recipients>"
  "contractArguments": {
     // JSON object with the arguments to the mint function and specified value
  }
}

Below is an example:

{
    "recipient": "email:<email address>:poly",
    "contractArguments": {
        "tokenCount_": 1,
        "signature": "0xabc..."
    }
}

With this request, users will receive the NFT in a custodial wallet associated with their email address.

Refer to the Crossmint Minting API docs and reference for more operations beyond basic minting, best practices, etc.