This tutorial aims to guide you through the process of creating and minting NFTs on one of the most efficient and cost-effective blockchain networks today, the Binance Smart Chain (BSC).
You will be learning how to do this using Crossmint's APIs.
This guide will take you approximately 10 minutes to complete.
Table of Contents:
- Setup
- Create an NFT Collection on BSC
- Create and Mint NFTs on BSC
- Create and Mint NFTs with No-code
- Conclusion
- What's Next?
- Need Help?
Setup
Before diving into the NFT creation and minting process on Binance Smart Chain (BSC) using Crossmint, let's understand the difference between Staging and Production environment.
Difference between Staging and Production
Crossmint provides two environments for developers: staging and production. The staging environment is designed for testing and development purposes. It's a replica of the production environment but doesn’t handle real transactions. Here, test credit cards are used, and it connects to testnets allowing for free API testing without actual blockchain costs. The staging URL is https://staging.crossmint.com.
The production environment, available at https://www.crossmint.com, is the live environment where real transactions occur. It demands actual credit card payments and interacts with the mainnet blockchains. Both environments require distinct API keys for interaction.
Creating a Developer Account and API Key
- Ensure a Developer Account is Active: Visit the Crossmint Console to set up a developer account if you haven't already. This is necessary to access API key management.
- Navigate to API Keys: In your Crossmint Console, locate the “API Keys” section. This is where all API key operations are managed.
- Generate a New Key: Click on “Create new key” to initiate a new API key. It's recommended to generate a server-side key for backend operations to ensure security.
Required Scopes for the API Key
For tasks involving creating a collection and minting NFTs on BSC, your API key should be configured with specific permissions. Essential scopes include:
- "nfts.create": Allows for the creation of NFTs.
- "nfts.read": Necessary for retrieving NFT details.
- "collections.create": Required to create new NFT collections.
- "collections.read": To read the collection details.
It's important to store the API key securely and use it appropriately within your application to authenticate and authorize operations against Crossmint services. Remember, staging and production environments require separate API keys to ensure the correct application behavior and data integrity across development and live operations.
Create an NFT Collection on BSC
Before we create and mint NFTs on BSC, we first need to create an NFT Collection. Let's learn how to do this.
Create a Collection
To start, ensure you have your API key ready, obtained from the Crossmint developer console, and choose whether you're working in the staging environment for testing or the production environment for live deployments. For this example, we'll use the production environment.
Here's how you create a collection on BSC:
const axios = require('axios');
async function createCollection() {
const url = 'https://www.crossmint.com/api/2022-06-09/collections/';
const apiKey = 'YOUR_API_KEY_HERE'; // Replace with your actual API key
const data = {
chain: 'bsc', // Blockchain to use
metadata: {
name: 'My Awesome NFT Collection',
imageUrl: 'https://example.com/my-collection-image.png',
description: 'This is a collection of my awesome NFTs',
symbol: 'AWSM' // Symbol for your collection
},
fungibility: 'non-fungible', // This collection is non-fungible
supplyLimit: 1000, // Max supply of tokens in the collection
payments: {
price: '0.01', // Price per token in the native currency (e.g., BNB for BSC)
recipientAddress: '0xYourWalletAddress' // Your wallet address to receive payments
},
reuploadLinkedFiles: true // Reupload linked files to IPFS
};
const config = {
headers: {
'X-API-KEY': apiKey
}
};
try {
const response = await axios.post(url, data, config);
const { id, actionId } = response.data;
console.log(`Collection Created. ID: ${id}, Action ID: ${actionId}`);
return { collectionId: id, actionId };
} catch (error) {
console.error('Error creating collection:', error.response.data);
}
}
After executing the code above, you'll receive an ID for your newly created collection and an action ID to track the deployment process. It's essential to note the action ID, as it will be used to verify if the collection was deployed successfully.
Verify Collection Deployment Using the ActionID
Once you've received an action ID, you can check the status of your collection deployment. The process may take a minute or more, depending on the current congestion of the blockchain.
async function verifyCollectionDeployment(actionId) {
const url = `https://www.crossmint.com/api/2022-06-09/actions/${actionId}`;
const apiKey = 'YOUR_API_KEY_HERE'; // Replace with your actual API key
const config = {
headers: {
'X-API-KEY': apiKey
}
};
try {
const response = await axios.get(url, config);
const { status, data } = response.data;
console.log(`Collection Deployment Status: ${status}`);
if (status === 'success') {
console.log('Collection successfully deployed. Contract Address:', data.collection.contractAddress);
} else if (status === 'pending') {
console.log('Collection deployment is still pending. Please check back later.');
} else {
console.log('Collection deployment failed.');
}
} catch (error) {
console.error('Error checking collection deployment status:', error.response.data);
}
}
This snippet polls the status of the collection deployment using the provided action ID. If the status is "success", it means the collection has been deployed to BSC, and you'll receive the contract address of your NFT collection. This contract address is crucial for minting NFTs to your collection in future steps.
By following these steps, you've successfully created an NFT collection on the Binance Smart Chain using Crossmint's API.
Create and Mint NFTs on BSC
Once your NFT collection is successfully deployed on the Binance Smart Chain (BSC), the next step is to create and mint NFTs within this collection.
Mint an NFT on the Created Collection
To mint an NFT, you need to make a POST request to the Crossmint API. Ensure to replace "YOUR_API_KEY" with your actual API key and "COLLECTION_ID" with the id of the collection where you intend to mint the NFT.
const axios = require('axios');
const collectionId = 'YOUR_COLLECTION_ID'; // Replace with your actual collection ID
const apiKey = 'YOUR_API_KEY'; // Replace with your Crossmint API key
const mintNFT = async () => {
const url = `https://www.crossmint.com/api/2022-06-09/collections/${collectionId}/nfts`;
try {
const response = await axios.post(url, {
recipient: "email:testy@crossmint.io:bsc", // Specify recipient
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 Minted: ", response.data);
return response.data; // This contains the action ID needed to verify the mint
} catch (error) {
console.error("Error minting NFT: ", error.response.data);
}
};
mintNFT();
In the request body, the "recipient" field specifies the recipient of the NFT. The format supports direct blockchain addresses or associating the minted NFT with an email. The "metadata" object contains details about the NFT, such as its name, image, and a brief description.
Verify the NFT was Minted Using the Action Id
After making the minting request, Crossmint provides an "actionId" as part of the response. This ID is essential for tracking the minting process. To verify the status of your NFT minting, execute the following command:
const actionId = 'YOUR_ACTION_ID'; // Replace with the action ID from mintNFT response
const verifyNFTMint = async (actionId) => {
const url = `https://www.crossmint.com/api/2022-06-09/actions/${actionId}`;
try {
const response = await axios.get(url, {
headers: {
'X-API-KEY': apiKey,
}
});
console.log("Mint Status: ", response.data);
} catch (error) {
console.error("Error getting mint status: ", error.response.data);
}
};
verifyNFTMint(actionId);
Replace "YOUR_ACTION_ID" with the action ID received from the minting request. The response provides the status of your action, which includes details about the minted NFT, such as the collection ID, recipient wallet address, and the token ID.
This command allows you to track the minting process and ensure that your NFT has been successfully minted and is ready for distribution or sale.
By following these steps, you have successfully created and minted an NFT on the Binance Smart Chain using the Crossmint platform.
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 below that teaches you how to do this with 0 code.
Conclusion
In this guide, we walked through the process of creating and minting NFTs on the Binance Smart Chain (BSC) using Crossmint. We've covered the crucial steps from setting up your developer environment in staging and production, creating an API key with the necessary scopes, establishing an NFT collection, and finally minting NFTs within that collection. By now, you should have a clear understanding of how to create and mint NFTs on BSC using Crossmint.
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.
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.