Rohit Ramesh profile image Rohit Ramesh

How to Create and Mint NFTs on Polygon

Learn how to create NFT Collections and mint NFTs on Polygon in a few mins using only simple API calls. You can also mint NFTs to an email address or a wallet address.

How to Create and Mint NFTs on Polygon

In this comprehensive tutorial, we're diving into the exciting world of NFT creation and distribution on the Polygon network utilizing Crossmint. Crossmint is an enterprise-grade platform that streamlines the integration of blockchain assets into various applications without the need for in-depth blockchain knowledge, making it particularly user-friendly.

Coupled with Polygon, a scalable layer two solution designed to enhance Ethereum's capabilities by improving its scalability and reducing costs, this tutorial offers a seamless path to launching your NFT projects.

Whether you're a developer looking to incorporate NFTs into your application or a creator eager to explore the potential of digital assets, this guide is your gateway. Expect to complete the integration in approximately 10 minutes, a small investment for the vast opportunities ahead.

Table of Contents:


Create and Mint NFTs with No-code

If you are wondering how you can create an NFT Collection and mint NFTs with no-code, please read the in-depth guide linked below that teaches you how to do this with 0 code.

How to Create an NFT Collection and Mint NFTs with 0 Code
In under 10 mins, learn how to create NFT Collections, create and mint NFTs with no-code.

However, the rest of this guide will show you how you can create NFT Collections and mint NFTs on Polygon using 2 simple API calls.

Setup

Before diving into creating and minting NFTs on Polygon using Crossmint, it's crucial to understand the environments in which you will be working and how to configure your tools correctly.

Difference Between Staging and Production

Crossmint provides two environments for developers: Staging and Production. The Staging environment is for testing and development purposes, allowing the use of test credit cards and testnets like Sepolia and Mumbai without real financial transactions or asset risks. Access it via https://staging.crossmint.com. Conversely, the Production environment is the live setting for real user interactions and transactions, accessed via https://www.crossmint.com. Transactions here occur on mainnets and involve actual financial implications.

Creating a Developer Account and API Key

  1. Verify Your Crossmint Developer Account: Ensure you have an account on the Crossmint Console. If not, sign up at https://www.crossmint.com/console and verify your account according to the platform's guidelines.
  2. Navigate to API Keys: Log into your Crossmint Developer Account and go to the "API Keys" section within the console. This area is dedicated to managing your API keys.
  3. Create a New API Key: Click "Create new key" and select the type of API key you require. For backend operations like minting NFTs, you'll need a Server-side API key.
  4. Select the Required Scopes: For NFT and wallet operations, enable scopes such as "nfts.create", "nfts.read", "collections.create", "collections.update", and "collections.read". Choose only those necessary for your project.
  5. Finalize and Secure Your Key: After selecting the required scopes, finalize the creation of your API key. Ensure to store your Server-side API key securely and not expose it in client-side code or public repositories.
Create and Mint NFTs on Polygon

Required Scopes for the API Key

The API key you create must include specific scopes to enable creating collections and minting NFTs. Essential scopes include "collections.create", for initializing NFT collections; "collections.update", for managing collection details; "collections.read", for retrieving collection information; and "nfts.create" and "nfts.read", for minting NFTs and accessing NFT data, respectively.

By setting up your environment and API key correctly, you'll be well-prepared for developing and launching NFT projects on Polygon with Crossmint.

Create an NFT Collection on Polygon

To launch an NFT collection on the Polygon blockchain, we'll leverage the Crossmint API. The process is straightforward and involves defining your collection's metadata and deploying it on the blockchain. Here, we'll break down the steps required to create and verify your NFT collection on Polygon.

Set up the API Request

First, ensure you have your Crossmint API key ready. This key is crucial for authentication and you'll need it for making API requests. You can get your API key from the Crossmint developer console.

const axios = require('axios').default;

const API_KEY = 'your_crossmint_api_key_here'; // Replace this with your API key
const BASE_URL = 'https://www.crossmint.com/api/2022-06-09/collections/';

In this step, we're importing Axios for making HTTP requests and setting up variables for our API key and the base URL targeting the Crossmint production environment, which will interact with mainnet blockchains like Polygon.

Define the NFT Collection

To create an NFT collection, define its characteristics such as name, image URL, description, and symbol. This information will be part of the collection's metadata.

const collectionData = {
  chain: "polygon", // Targeting the Polygon blockchain
  metadata: {
    name: "My Awesome NFT Collection",
    imageUrl: "https://example.com/my-collection-image.png",
    description: "A collection of unique digital assets",
    symbol: "MAWC" // This is an optional field for EVM chains like Polygon
  },
  fungibility: "non-fungible", // Set to 'non-fungible' for unique items
  supplyLimit: 1000, // Maximum number of tokens that can be minted
};

Here, we have a JavaScript object "collectionData" housing the configuration for our collection. Adjust these fields as per your collection's specifics.

Create the Collection

Now that we have our collection details defined, we'll make a POST request to the Crossmint API to create the collection.

axios.post(BASE_URL, collectionData, {
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': API_KEY,
  },
})
.then(response => {
  console.log("Collection created successfully:", response.data);
  verifyCollectionDeployment(response.data.actionId);
})
.catch(error => {
  console.error("Failed to create collection:", error.response?.data || error.message);
});

In this step, we're sending a POST request with our collection data and including our API key in the request headers for authentication. Upon success, we log the response data.

Verify Collection Deployment

After creating the collection, use the returned "actionId" to verify the deployment status on the blockchain.

function verifyCollectionDeployment(actionId) {
  const actionStatusUrl = `https://www.crossmint.com/api/2022-06-09/actions/${actionId}`;

  axios.get(actionStatusUrl, {
    headers: {
      'X-API-KEY': API_KEY,
    },
  })
  .then(statusResponse => {
    console.log("Deployment Status:", statusResponse.data);
  })
  .catch(error => {
    console.error("Failed to verify deployment:", error.response?.data || error.message);
  });
}

This function polls the status of the collection creation process using the action ID we received. It's important to ensure that the collection is successfully deployed before proceeding to mint NFTs within it.

With these steps, you have created an NFT collection on the Polygon network using the Crossmint API. The process involves setting up your request, defining the collection, creating it via the API, and then verifying its deployment.

Create and Mint NFTs on Polygon

After successfully creating your NFT collection on the Polygon blockchain through Crossmint, the next step is to mint NFTs within that collection. Minting is the process of publishing your digital artwork or assets as NFTs onto the blockchain, making them purchasable or tradable assets. In this section, we will guide you through minting an NFT to a specific collection on Polygon using the Crossmint API.

Mint an NFT on the Created Collection

First, ensure you have the "collectionId" of the collection you created in the previous steps. This ID will be used to specify where the NFT should be minted. Let’s start by minting an NFT to our collection. The recipient of the NFT can be specified either by their blockchain address or by their email address. Here, we will use the recipient’s email address for simplicity.

const axios = require('axios');
const apiKey = 'YOUR_CROSSMINT_API_KEY'; // Replace with your API key
const collectionId = 'YOUR_COLLECTION_ID'; // Replace with your collection ID obtained from the create-collection endpoint

const mintNFT = async () => {
  try {
    const response = await axios.post(`https://www.crossmint.com/api/2022-06-09/collections/${collectionId}/nfts`, {
      recipient: 'email:testy@crossmint.io:polygon',
      metadata: {
        name: "Crossmint Example NFT",
        image: "https://www.crossmint.com/assets/crossmint/logo.png",
        description: "My NFT created via the mint API!"
      }
    }, {
      headers: {
        'X-API-KEY': apiKey
      }
    });

    console.log('NFT Mint Response:', response.data);
    return response.data.actionId; // We will use the returned action ID to verify the minting status.
  } catch (error) {
    console.error('Error minting NFT:', error.response.data);
  }
};

mintNFT();

This code snippet sends a POST request to the Crossmint API to mint a new NFT in the specified collection. We provide the recipient's information and metadata about the NFT, such as its name, image, and description. On success, it logs the response, which includes an "actionId" that we can use to verify if the NFT was minted successfully.

Verify the NFT was Minted Using the Action ID

After initiating the minting process, it’s important to check the status of the minting action to ensure it was completed successfully. Here’s how you can do that using the "actionId" received from the minting request:

const verifyMint = async (actionId) => {
  try {
    const response = await axios.get(`https://www.crossmint.com/api/2022-06-09/actions/${actionId}`, {
      headers: {
        'X-API-KEY': apiKey
      }
    });

    console.log('Mint Verification Response:', response.data);
  } catch (error) {
    console.error('Error verifying mint:', error.response.data);
  }
};

// Assuming mintNFT() was called and returned an actionId
mintNFT().then(verifyMint);

This script sends a GET request to Crossmint’s API to retrieve the status of our mint action using the "actionId". If the minting process was successful, we should see a response indicating that the action has been completed, along with information about the newly minted NFT.

By following these steps, you can create and mint NFTs on the Polygon blockchain using the Crossmint API. This process allows artists, developers, and businesses to easily integrate NFT minting into their applications, leveraging the power of blockchain technology.

Conclusion

In this guide, we walked through the process of creating and minting NFTs on the Polygon blockchain using Crossmint. We started by setting up our environment and creating an API key, proceeded to create an NFT collection, and then minted NFTs to that collection. Finally, we verified the success of our actions using the action id. This practical approach equips you with the fundamental knowledge needed to launch your NFT project on Polygon efficiently.

What's Next?

If you are wondering how Crossmint has helped enterprises and brands by powering their NFT Drops, you can click on the link below to read all our Case Studies.

Case Studies
Access 25+ case studies, across industries, from the 30,000+ companies that have used Crossmint’s infrastructure.

If you want to learn how to use the Crossmint to create Web 3 NFT Wallets for your users using their Email Address, please watch the YouTube video below.

Need help?

For support, please join the official Crossmint Discord Server. You can also use Crossmint Help Page for the same.

Enable Crosschain Payments on Polygon | Crossmint
This guide will show you how to enable NFT Crosschain Payment on Polygon with Crossmint.
Create an NFT Storefront with 0 Code | Crossmint
With Crossmint’s No-Code Storefronts, you can start selling NFTs right now, with cross-chain and credit card payments automatically activated
Sign up developer console
Rohit Ramesh profile image Rohit Ramesh
DevRel Engineer at Crossmint