Gold Logo

Program Examples

These code examples demonstrate how to interact with the Gold Digger Factory Program using the Anchor framework. Each example includes detailed comments to help you understand the process.

Minting an NFT

Create and mint a new NFT with metadata using the Gold Digger Factory Program

import * as anchor from '@project-serum/anchor';
import { GoldDiggerFactory } from '../target/types/gold_digger_factory';
import { Metaplex } from '@metaplex-foundation/js';

async function mintNFT() {
  // Initialize connection and wallet
  const connection = new anchor.web3.Connection('https://api.mainnet-beta.solana.com');
  const wallet = useWallet(); // Your wallet adapter
  
  // Initialize program
  const provider = new anchor.AnchorProvider(connection, wallet, {});
  const program = new anchor.Program<GoldDiggerFactory>(IDL, PROGRAM_ID, provider);
  
  // Create mint account
  const mint = anchor.web3.Keypair.generate();
  
  // Prepare metadata
  const metadata = {
    name: "Gold Digger NFT #1",
    symbol: "GOLD",
    uri: "https://arweave.net/your-metadata-uri",
  };
  
  // Execute mint instruction
  await program.methods
    .mintNft(metadata.uri, metadata.name)
    .accounts({
      mint: mint.publicKey,
      metadata: await getMetadataAddress(mint.publicKey),
      payer: wallet.publicKey,
      systemProgram: anchor.web3.SystemProgram.programId,
      tokenProgram: TOKEN_PROGRAM_ID,
      tokenMetadataProgram: METADATA_PROGRAM_ID,
      rent: anchor.web3.SYSVAR_RENT_PUBKEY,
    })
    .signers([mint])
    .rpc();
    
  console.log("NFT minted successfully:", mint.publicKey.toString());
  return mint.publicKey;
}

// Helper function to get metadata address
async function getMetadataAddress(mint: anchor.web3.PublicKey): Promise<anchor.web3.PublicKey> {
  const metaplex = new Metaplex(connection);
  return metaplex.nfts().pdas().metadata({ mint });
}

Using the Examples

To use these examples in your project, you'll need to:

  1. Install the required dependencies: @project-serum/anchor, @metaplex-foundation/js
  2. Generate the IDL file from the Gold Digger Factory Program
  3. Set up a wallet adapter for your frontend application
  4. Modify the examples to fit your specific use case

Important Note

These examples are simplified for demonstration purposes. In a production environment, you should implement proper error handling, transaction confirmation, and retry logic.