A Solana smart contract built with Anchor for minting NFTs with a capped collection size of 444. This program integrates Metaplex Token Metadata for standardized NFT creation.
- Capped Collection: Limits the total number of NFTs minted to 444.
- Metaplex Metadata: Utilizes Metaplex's Token Metadata standard for NFT attributes.
- Mint Tracking: Uses a counter account to track the number of NFTs minted.
- Cross-Program Invocation (CPI): Creates metadata accounts via CPI with Metaplex's Token Metadata program.
- Solana CLI: Install from Solana Docs.
- Rust: Install from Rust-Lang.
- Anchor 0.30.1: Install with
cargo install --git https://github.com/coral-xyz/anchor anchor-cli --locked --force. - Node.js: Recommended version 16.x or higher.
- Metaplex Token Metadata v5.1.0: Included via Cargo.toml dependency.
- Clone the Repository:
git clone https://github.com/your-repo/nft-mint-program.git
cd nft-mint-program- Install Dependencies:
npm install- Build the Program:
anchor build- mint_counter: PDA (Program Derived Address) tracking the total minted NFTs (max 444).
- mint: The NFT mint account (SPL Token).
- metadata: Metaplex metadata account storing NFT attributes (name, symbol, URI, etc.).
- token_account: Associated Token Account (ATA) for the payer to receive the minted NFT.
- payer: The wallet signing and funding the transaction.
The mint_nft instruction:
- Checks the mint_counter to enforce the 444 NFT limit.
- Creates a metadata account via CPI with Metaplex.
- Mints 1 token to the payer's ATA.
- Increments the mint_counter.
- Private Keys: Excluded via .gitignore. Never commit target/, node_modules/, or wallet keypairs.
- Audits: Review code and dependencies before deployment.
- Environment: Use a secure wallet and avoid exposing sensitive data in client-side code.
To avoid compilation errors with Anchor and Anchor-SPL IDLs, update Cargo.toml with:
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]This ensures the IDL is built correctly for both Anchor and Anchor-SPL dependencies.
This code is for educational purposes. Audit and test thoroughly before deploying to mainnet.