Skip to main content

Minting

Immutable's SDK simplifies token minting for content creators, allowing them to mint tokens from their deployed NFT collections.

This guide covers the core concepts of minting and provides references to guides on how to effectively mint on Immutable zkEVM.


blockchain minting api asset relationships
💡Minting tutorial

For a step-by-step guide on how to mint an NFT on zkEVM, including contract deployment, check out our Create game assets tutorial.

What is minting?

Minting an NFT (non-fungible token) involves creating a unique digital asset on the blockchain, representing items like art, music, videos, or collectibles, whose ownership and authenticity can be verified.

In Web3 gaming, minting often refers to generating and assigning in-game assets to players.

Why do I need to deploy a smart contract before I can mint tokens?

Before minting an NFT (non-fungible token), the first step is to deploy an ERC721 contract on the blockchain. Smart contracts serve as essential blueprints for the NFTs they create, encompassing a range of functions that facilitate the maintenance of the collection and its associated tokens. Among these functions is the capability to mint new NFTs.

ERC721 contracts are designed specifically for managing NFTs, offering a set of rules and functions that govern the creation, ownership, and transfer of unique digital assets. These contracts play a crucial role in enabling the seamless handling of non-fungible tokens, ensuring their uniqueness, scarcity, and ownership rights within the blockchain ecosystem.

More information:

Minting and gas fees

Deploying new ERC721 contracts and minting NFTs from these contracts update the blockchain, resulting in gas fees denominated in a unit called "gas." Gas represents the computational effort needed to process and validate transactions, execute smart contracts, and perform other operations on the network.

Gas fees serve several vital purposes:

  1. Preventing network abuse: By imposing a cost on executing operations, gas fees discourage malicious actors from overloading the network with excessive or spam transactions.
  2. Resource allocation: Gas fees ensure that resources, such as computational power and storage, are appropriately allocated to process transactions and execute smart contracts, maintaining network efficiency.
  3. Incentivizing miners/validators: Miners or validators who include transactions in a block and validate them receive gas fees as a reward for their work. This incentivizes participants to validate transactions, supporting network security and integrity.

To mint a new NFT, a wallet is required to cover the associated gas fees. It's worth noting that the minting method you choose can influence the amount of gas required for various actions.

How do I mint an NFT from a deployed ERC721 contract?

Check out the Mint tokens step in our Create game assets tutorial for full instructions on how to mint tokens from a deployed smart contract.

How do I batch mint an NFT from a deployed ERC721 contract?

Minting in batches if more efficent than single mint requests and can end up saving a game studio and player significant gas fees. Immutable's contract presets contains the mintBatch([CONTRACT_ADDRESS, TOKEN_ID]) which accepts an array of wallet addresses and Token IDs to mint a batch of NFTs with a single request. To use the batch mint function, deploy Immutable's contract presets; then create the following script

  • CONTRACT_ADDRESS - The address of the deployed preset contract
  • PRIVATE_KEY - The private key of the wallet that is paying the gas fees of the mint request
info

Find a more detailed explanation about how to interact with your deployed collection here.

import { getContract, http, createWalletClient, defineChain } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { ImmutableERC721Abi } from '@imtbl/contracts';

const PRIVATE_KEY = 'YOUR_PRIVATE_KEY'; // should be read from environment variable
const CONTRACT_ADDRESS = '0xYOUR_CONTRACT_ADDRESS'; // should be of type `0x${string}`
const ANOTHER_RECIPIENT = '0xRECIPIENT_ADDRESS';

const immutableTestnet = defineChain({
id: 13473,
name: 'imtbl-zkevm-testnet',
nativeCurrency: { name: 'IMX', symbol: 'IMX', decimals: 18 },
rpcUrls: {
default: {
http: ['https://rpc.testnet.immutable.com'],
},
},
});

const walletClient = createWalletClient({
chain: immutableTestnet,
transport: http(),
account: privateKeyToAccount(`0x${PRIVATE_KEY}`),
});

// Bound contract instance
const contract = getContract({
address: CONTRACT_ADDRESS,
abi: ImmutableERC721Abi,
client: walletClient,
});

const batchMint = async (): Promise<string> => {
// We can use the read function hasRole to check if the intended signer
// has sufficient permissions to mint before we send the transaction
const minterRole = await contract.read.MINTER_ROLE();

const hasMinterRole = await contract.read.hasRole([
minterRole,
walletClient.account.address,
]);

if (!hasMinterRole) {
// Handle scenario without permissions...
console.log('Account doesnt have permissions to mint.');
return Promise.reject(
new Error('Account doesnt have permissions to mint.')
);
}
// Specify who we want to receive the minted token
const recipient = walletClient.account.address;

// Construct list of tokens to mint
const mintRequests = [
{
to: recipient,
tokenIds: [BigInt(2), BigInt(3), BigInt(4)],
},
{
to: ANOTHER_RECIPIENT as `0x${string}`,
tokenIds: [BigInt(5), BigInt(6), BigInt(7)],
},
];

const txHash = await contract.write.safeMintBatch([mintRequests]);

console.log(`txHash: ${txHash}`);
return txHash;
};

batchMint();

Congratulations you have just created your first batch of NFTs with Token ID 2, 3 & 4 to the CONTRACT_ADDRESS wallet specified.

For more information on batch minting, have a look at our Batch Minting product guide

What happens once an NFT is minted?

Once an NFT is successfully minted, it becomes a permanent record on the blockchain. While on-chain data is publicly accessible, off-chain metadata remains private. Upon successful minting, Immutable's search engine is activated, indexing the NFT's metadata for efficient retrieval and discovery.

For additional details on Immutable's indexer, please refer to our Blockchain Data guide.

IMX Whitepaper IMX Tokenomics Block Explorer Careers Contact Us