Subscribe to our Blog

Subscribe to Crossmint's blog for free to receive updates on the latest studies, Web3 technical guides, and more.

Subscribe Crossmint Blog cover image
Rohit Ramesh profile image Rohit Ramesh

How to Create and Mint NFTs on Base

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

How to Create and Mint NFTs on Base

In this guide, you are going to learn how to create and mint Non-Fungible Tokens (NFTs) on Base using Crossmint.

By the end, you will learn how to:

This guide will take you 10 mins to complete (approximately).

Let's get started!

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 Base using 2 simple API calls.

Setup

Before we create and mint NFTs on Base using Crossmint, we first need to understand the distinction between the different environments at Crossmint. You also need to learn how to create an API key and configure the necessary scopes for it.

Difference between Staging and Production

Crossmint has two different environments, they are, Staging and Production.

The staging environment serves as a test bed, mimicking the production setup without affecting the live version. It's accessible via https://staging.crossmint.com and allows developers to deploy and test their features in a risk-free setting.

Conversely, the production environment, found at https://www.crossmint.com, is where the live, user-facing application resides. Changes here are public and have real-world implications.

Creating a Developer Account and API Key

Creating an API key is crucial for integrating Crossmint functionalities within your app, especially for server-side operations like NFT minting.

Follow these steps:

  1. Create a Developer Account: Create a Developer Account on Crossmint Console if you haven't already.
  2. Navigate to API Keys Section: Log into Crossmint's Console and navigate to "Developers" section and click on "API Keys".
  3. Choose the Type of API Key: Opt for a Server-side API Key required for operations like NFT collection creation or minting.
  4. Select Scopes: When prompted, select scopes that determine the API key’s access level. Essential scopes include:
    1. "nfts.create"
    2. "nfts.read"
    3. "collections.create"
    4. "collections.read"

These scopes will allow the API key to create NFT Collections and create NFTs.

Create and Mint NFTs on Base

Create an NFT Collection on Base

Before you create NFTs on Base, you first need to create an NFT Collection on Base. Let's learn how to do this!

Prepare Your Collection's Metadata

The first step is to define the characteristics (metadata) of your NFT collection. This includes the name, image URL representing the collection, a description, and the collection symbol (for EVM only).

Here's an example of how to prepare this metadata:

const collectionMetadata = {
  chain: "base", // Specify 'base' for the Base blockchain
  metadata: {
    name: "My Unique NFT Collection", // Your collection's name
    imageUrl: "https://www.example.com/collection-image.png", // URL of the collection's representative image
    description: "A collection of unique digital assets.", // Description of your collection
    symbol: "UNQ" // Collection symbol (EVM chains only)
  },
  fungibility: "non-fungible", // Specify whether the collection is non-fungible or semi-fungible
  supplyLimit: 1000, // The maximum number of NFTs in the collection
  payments: {
    price: "0.01", // Price per NFT in the native currency
    recipientAddress: "0xYourWalletAddress" // Your wallet address to receive payments
  },
  reuploadLinkedFiles: true // Indicates if URLs in metadata should be reuploaded to IPFS
};

Make sure to replace the placeholders ("https://www.example.com/collection-image.png" and "0xYourWalletAddress") with your actual collection image URL and recipient wallet address.

Create the NFT Collection

With the metadata ready, you can now proceed to create the collection by making a POST request to the Crossmint API. Ensure you've obtained your API key from the Crossmint developer console and have it readily available.

const axios = require('axios'); // Ensure you have axios installed

const createCollection = async (metadata) => {
  const API_URL = "https://www.crossmint.com/api/2022-06-09/collections/";
  const API_KEY = "your_api_key_here"; // Replace with your actual Crossmint API key
  
  try {
    const response = await axios.post(API_URL, metadata, {
      headers: {
        "X-API-KEY": API_KEY,
      },
    });
    
    console.log("Collection created successfully:", response.data);
    return response.data; // This includes the collection ID and action ID
  } catch (error) {
    console.error("Failed to create collection:", error.response.data);
  }
};

createCollection(collectionMetadata).then((data) => {
  console.log("Created Collection ID:", data.id);
  console.log("Deployment Action ID:", data.actionId);
});

This script makes a POST request to the Crossmint API to create your NFT collection. Upon success, it logs the collection ID and the action ID, which is important for tracking the deployment status.

Verify Deployment Status

After creating your collection, you should verify that it has been deployed successfully on the blockchain. You can do this by polling for the status of the deployment action using the action ID returned in the previous step.

const ACTION_ID = "your_action_id_here"; // Replace with your actual action ID

const checkDeploymentStatus = async (actionId) => {
  const API_URL = `https://www.crossmint.com/api/2022-06-09/actions/${actionId}`;
  
  try {
    const response = await axios.get(API_URL, {
      headers: {
        "X-API-KEY": API_KEY,
      },
    });
    
    console.log("Deployment Status:", response.data.status);
    return response.data.status; // This is the status of your collection's deployment
  } catch (error) {
    console.error("Failed to check deployment status:", error.response.data);
  }
};

checkDeploymentStatus(ACTION_ID).then((status) => {
  if (status === "success") {
    console.log("Your collection has been deployed successfully!");
  }
});

Replace "your_action_id_here" with the actual action ID you received from creating the collection. This script will check the status of the deployment and log whether it has been successfully deployed to the blockchain.

Following these steps will successfully create your NFT collection on Base using the Crossmint API. The collection is now ready for minting NFTs, which we will cover in the next section.

Create and Mint NFTs on Base

In this section, we’ll go through the steps required to create and mint your own NFTs on the Base blockchain using the Crossmint API. We assume you've already created a collection as detailed in the previous section.

Mint an NFT on the Created Collection

To mint an NFT, you will use the collection ID of the collection you created. You'll specify metadata for your NFT, which includes a name, image, and description, and the recipient information.

First, ensure you have the "collectionId" from the collection creation step. Then, prepare your NFT metadata and recipient details. Here's how you can do it in JavaScript:

const axios = require('axios');
const apiKey = 'YOUR_CROSSMINT_API_KEY';
const collectionId = 'YOUR_COLLECTION_ID'; // Replace with your actual collection ID
const nftMetadata = {
  name: "Crossmint Example NFT",
  image: "https://www.crossmint.com/assets/crossmint/logo.png",
  description: "My NFT created via the mint API!"
};
const recipient = "email:testy@crossmint.io:base"; // Example recipient format

axios.post(`https://www.crossmint.com/api/2022-06-09/collections/${collectionId}/nfts`, {
  recipient,
  metadata: nftMetadata
}, {
  headers: {
    'X-API-KEY': apiKey
  }
})
.then(response => {
  console.log("Mint Response:", response.data);
})
.catch(error => {
  console.error("Error minting NFT:", error);
});

In this code snippet, you replace "YOUR_CROSSMINT_API_KEY" with your actual API key and "YOUR_COLLECTION_ID" with the collection ID you received from creating your NFT collection. The recipient in this example uses an email and chain format, but you can replace it with a direct wallet address if preferred.

Replace the email address with the target email address that you want to mint the NFT to.

Verify the NFT was Minted Using the Action ID

After minting your NFT, you'll receive an actionId in the response. You can use this ID to check the status of the minting process. Below is how you can poll for the minting status:

const actionId = 'YOUR_ACTION_ID_FROM_MINTING'; // Replace with your actual action ID

const checkMintingStatus = () => {
  axios.get(`https://www.crossmint.com/api/2022-06-09/actions/${actionId}`, {
    headers: {
      'X-API-KEY': apiKey
    }
  })
  .then(statusResponse => {
    console.log("Minting Status:", statusResponse.data);
    if(statusResponse.data.status !== 'completed') {
      console.log("Minting in progress, check back later.");
    } else {
      console.log("Minting completed successfully.");
    }
  })
  .catch(error => {
    console.error("Error checking minting status:", error);
  });
}

// Initial check
checkMintingStatus();

// Optionally, set an interval to poll periodically
// setInterval(checkMintingStatus, 60000); // Check every 60 seconds

Replace "YOUR_ACTION_ID_FROM_MINTING" with the action ID you received from the minting response. This script first makes an immediate check on the minting status and logs the result. Optionally, you can enable the "setInterval" line to have it check periodically until the minting is confirmed as completed.

And that's it! You have now learned how to mint NFTs onto your NFT collection on the Base blockchain using the Crossmint API.

Conclusion

In this guide, we learned the steps necessary to create and mint NFTs on Base, starting from setting up an API key with the appropriate scopes to creating a collection and minting NFTs within it.

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 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.

Enabling NFT Cross Chain Payment on Ethereum Layer 2
This guide will show you how to enable cross chain payment on Ethereum Layer 2s such as Base or Optimism with Solana and Ethereum on mainnet.
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