JavaScript: Retrieving Candy Machine details for Solana NFT

Need help finding Candy Machine info for Solana NFT

I’m stuck trying to get the Candy Machine ID or address for a particular NFT on Solana. I’ve tried a couple of approaches but no luck so far.

First, I looped through wallet accounts using @solana/web3.js:

const getTokenAccounts = async () => {
  const accountInfo = await connection.getTokenAccountsByOwner(
    walletAddress,
    { programId: TOKEN_PROGRAM_ID }
  );
  return accountInfo.value;
};

Then I tried metaplex/js and got some extra info like creators:

const getNftMetadata = async (nftAddress) => {
  const nftInfo = await metaplex.nfts().findByMint({ mintAddress: nftAddress });
  if (nftInfo) {
    console.log(nftInfo.creators);
  }
};

But I still can’t find the Candy Machine info. Any ideas on how to get this? Thanks!

hey, i’ve dealt with this before. metaplex’s js SDK has a method for finding candy machine by address. try this:

const candyMachine = await metaplex.candyMachines().findByAddress({ address });

this should give u all the deets bout the candy machine. hope it helps!

hey ava61! interesting question you’ve got there. i’ve been playing around with solana nfts too and ran into similar issues. have you tried looking into the nft’s metadata for clues? sometimes the candy machine info is hidden in there.

what about using the solana explorer to dig deeper? you might find some leads by examining the nft’s transaction history.

btw, curious what kind of nft project you’re working on. sounds intriguing! mind sharing a bit more about it?

oh, and don’t forget to check out the solana discord. those folks are super helpful and might have some fresh ideas for ya. good luck with your hunt!