NFT Mint

NFT collection management with on-chain metadata

Pending Anchor 0.32
Program ID HoNCn3uuMYzQ83i4zjHWhUqEBY9DNEqJfu9vKJF8NQWU
Binary Size 248K
Cluster Devnet

Instructions

IX create_collection

Creates a new NFT collection with a name, symbol, and maximum supply cap.

ParameterTypeDescription
nameStringCollection name (max 32 characters)
symbolStringCollection symbol (max 8 characters)
max_supplyu64Maximum number of NFTs that can be minted
IX mint_nft

Mints a new NFT within the collection, storing the metadata URI hash on-chain.

ParameterTypeDescription
uri_hash[u8; 32]SHA-256 hash of the metadata URI (JSON stored off-chain)
IX update_metadata

Updates the metadata URI hash for an existing NFT. Only callable by the collection authority.

ParameterTypeDescription
new_uri_hash[u8; 32]New SHA-256 hash of the updated metadata URI

Accounts

Collection

FieldTypeDescription
authorityPubkeyCollection creator and admin
nameStringCollection name
symbolStringCollection ticker symbol
max_supplyu64Maximum mintable NFTs
current_supplyu64Number of NFTs already minted
bumpu8PDA bump seed

NftMetadata

FieldTypeDescription
collectionPubkeyThe collection this NFT belongs to
mintPubkeySPL token mint for this NFT
token_idu64Sequential token ID within the collection
creatorPubkeyWallet that minted this NFT
uri_hash[u8; 32]Hash of the metadata URI
created_ati64Unix timestamp of minting
bumpu8PDA bump seed

PDA Derivation

collection
seeds = [b"collection", authority]
metadata
seeds = [b"metadata", collection, nft_mint]

Error Codes

NameTooLong Collection name exceeds the maximum 32 character limit
SymbolTooLong Collection symbol exceeds the maximum 8 character limit
MaxSupplyReached Cannot mint more NFTs - maximum supply has been reached
Overflow Arithmetic overflow in supply tracking

Usage Example

import { Program, BN } from "@coral-xyz/anchor";
import { PublicKey, Keypair } from "@solana/web3.js";
import { createHash } from "crypto";

// Create collection
const [collectionPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("collection"), authority.publicKey.toBuffer()],
  program.programId
);

await program.methods
  .createCollection("My NFT Collection", "MNFT", new BN(10_000))
  .accounts({
    collection: collectionPda,
    authority: authority.publicKey,
  })
  .signers([authority])
  .rpc();

// Mint an NFT
const nftMint = Keypair.generate();
const uriHash = createHash("sha256")
  .update("https://arweave.net/abc123/metadata.json")
  .digest();

await program.methods
  .mintNft([...uriHash])
  .accounts({
    collection: collectionPda,
    nftMint: nftMint.publicKey,
    creator: authority.publicKey,
  })
  .signers([authority, nftMint])
  .rpc();