In the Solana Candy Machine V2 program, you can retrieve all the NFTs created by one candy machine using the program's state data. To do this, you'll need to interact with the Solana blockchain and query the state of the candy machine.

Here's a general outline of the steps to get all the NFTs created by a specific candy machine using JavaScript:

  1. Connect to Solana Network: Use a Solana Web3 library (e.g., @solana/web3.js) to connect to the Solana network. You'll need a wallet provider to sign transactions.

  2. Get the Candy Machine ID: Identify the specific candy machine you're interested in by its ID or public key. You can obtain this ID from your contract deployment or other relevant sources.

  3. Query Candy Machine State: Using the Solana Web3 library, query the candy machine's state data. The candy machine state contains information about the NFTs created, including their metadata, token URIs, and owner addresses.

  4. Parse the State Data: Parse the state data to extract the relevant information about the NFTs created by the candy machine.

  5. Retrieve NFT Metadata: Use the metadata and token URI information to access and display the details of each NFT.

Here's a high-level code example using @solana/web3.js to demonstrate how you can get the NFTs created by a specific candy machine:

const { Connection, PublicKey } = require('@solana/web3.js'); async function getAllNFTsByCandyMachine(candyMachineId) { // Connect to the Solana network const connection = new Connection(''); try { // Convert the candy machine ID to a PublicKey object const candyMachinePublicKey = new PublicKey(candyMachineId); // Fetch the candy machine's state data const candyMachineState = await connection.getAccountInfo(candyMachinePublicKey); // Parse the state data to get information about the NFTs // The structure of the state data may vary based on your candy machine implementation // Access and display the NFT metadata using the token URIs and other relevant data // Example: Access the number of NFTs created const numNFTsCreated =; console.log(`Number of NFTs created: ${numNFTsCreated}`); } catch (error) { console.error('Error fetching candy machine state:', error); } } // Replace 'candyMachineId' with the actual candy machine ID you want to query getAllNFTsByCandyMachine('candyMachineId');

Please note that the exact structure of the candy machine state data and NFT metadata may depend on the specific implementation of your Solana Candy Machine V2 program. You may need to adapt the code to match your contract's state structure and data retrieval methods.

Additionally, make sure you have the correct candy machine ID and that the candy machine has been deployed and contains NFTs in its state. The code above serves as a general guide to help you get started with retrieving NFTs created by a specific candy machine on the Solana network.

Have questions or queries?
Get in Touch