Crossmint allows you to use your own smart contract while leveraging our infrastructure for minting NFTs. This guide will walk you through the process of integrating your custom smart contract with Crossmint.

Prerequisites

Before you can use your own smart contract with Crossmint, ensure that:

  1. Your smart contract has a free minting function that allows Crossmint to mint NFTs without paying for gas.
  2. Your smart contract complies with the ERC721 standard (for NFTs) or ERC1155 standard (for SFTs).

Currently, this feature is only available for EVM chains. Support for Solana and other chains is coming soon.

Integration Guide

1. Register Your Smart Contract

First, you need to register your smart contract with Crossmint:

cURL
curl --request POST \
  --url https://staging.crossmint.com/api/2022-06-09/collections/custom \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: <api-key>' \
  --data '{
  "chain": "polygon",
  "contractAddress": "0x123...",
  "metadata": {
    "name": "My Custom Collection",
    "description": "A collection using my own smart contract"
  }
}'

2. Contract Review

After registering your contract, the Crossmint team will review it to ensure compatibility with our infrastructure. This typically takes 1-2 business days.

During the review process, we’ll verify that your contract has the necessary free minting function and complies with the required standards.

3. Mint NFTs

Once your contract is approved, you can start minting NFTs using the Crossmint API:

cURL
curl --request POST \
  --url https://staging.crossmint.com/api/2022-06-09/collections/{collectionId}/nfts \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: <api-key>' \
  --data '{
  "recipient": "polygon:0x123...",
  "contractFunction": {
    "name": "mintTo",
    "params": [
      {
        "name": "to",
        "type": "address",
        "value": "$RECIPIENT_ADDRESS"
      },
      {
        "name": "tokenId",
        "type": "uint256",
        "value": "1"
      }
    ]
  }
}'

The $RECIPIENT_ADDRESS placeholder will be automatically replaced with the recipient’s address by Crossmint.

Contract Function Parameters

When using your own smart contract, you need to specify the contract function to call and its parameters:

  • name: The name of the function in your smart contract that mints NFTs.
  • params: An array of parameters to pass to the function.
    • name: The parameter name as defined in your smart contract.
    • type: The parameter type (e.g., address, uint256, string).
    • value: The value to pass to the parameter.

You cannot pass custom metadata as a parameter. Metadata is controlled at the smart contract level when using your own contract.

Example: Minting with a Custom Contract

Here’s an example of minting an NFT using a custom contract with a mintTo function:

const apiKey = "YOUR_API_KEY";
const collectionId = "your-custom-collection-id";
const env = "staging"; // or "www" for production
const recipient = "polygon:0x123..."; // Recipient's wallet address

const url = `https://${env}.crossmint.com/api/2022-06-09/collections/${collectionId}/nfts`;
const options = {
    method: "POST",
    headers: {
        accept: "application/json",
        "content-type": "application/json",
        "x-api-key": apiKey,
    },
    body: JSON.stringify({
        recipient,
        contractFunction: {
            name: "mintTo",
            params: [
                {
                    name: "to",
                    type: "address",
                    value: "$RECIPIENT_ADDRESS",
                },
                {
                    name: "tokenId",
                    type: "uint256",
                    value: "42",
                },
            ],
        },
    }),
};

fetch(url, options)
    .then((response) => response.json())
    .then((data) => console.log("NFT minted:", data))
    .catch((error) => console.error("Error minting NFT:", error));

Best Practices

When using your own smart contract with Crossmint:

  1. Test Thoroughly: Test your contract integration in the staging environment before moving to production.
  2. Function Visibility: Ensure your minting function has the appropriate visibility and access controls.
  3. Gas Optimization: Optimize your contract to minimize gas costs for minting operations.
  4. Error Handling: Implement proper error handling in your contract to provide meaningful error messages.

FAQs