4

I am trying to find out what is the candy machine id or address for a specific nft.

So far I have tried looping through wallet accounts using @solana/web3.js

const tokenAccounts = await connection
        .getParsedTokenAccountsByOwner(publicKey, {
          programId: TOKEN_PROGRAM_ID,
        })
        .then((context) => context.value);

Also tried metaplex/js, I got some more info like creators:

const mintAccount = new metaplex.Account(searchNftAddress, mintAccInfo);
          if (mintAccount) {
            const metadata = metaplex.programs.metadata.Metadata.from(mintAccount);
            console.log(metadata.data?.data?.creators);
          }

But I do not find candy machine info.

Eduardo
  • 1,781
  • 3
  • 26
  • 61

2 Answers2

1

If I understand well, do you wan to know the owner of a specific NFT?

This works for me, I took it from here https://solanacookbook.com/references/nfts.html#candy-machine-v1

import {Connection, clusterApiUrl, PublicKey} from '@solana/web3.js';

const connection = new Connection(clusterApiUrl('mainnet-beta'));

export const getOwnerAddresses = async (tokenMint) => {
    //const connection = new Connection('https://api.mainnet-beta.solana.com');

    const largestAccounts = await connection.getTokenLargestAccounts(new PublicKey(tokenMint));
    const largestAccountInfo = await connection.getParsedAccountInfo(largestAccounts.value[0].address);
    //console.log(largestAccountInfo.value.data);
    console.log(largestAccountInfo.value.data.parsed.info.owner);
    /*
    PublicKey {
        _bn: <BN: 6ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9>
    }
     */
};

You just only have to create import the module and use it like this:

getOwnerAddresses('XXXXXXXXX');
Kangulo
  • 41
  • 2
0

I think when you upload the nfts, in cache folder, a new json will be created and you get the id from there:

{
  "program": {
    "uuid": "Wzsae7",
    "config": "Serai5EV4oisGhcZHYHGaL4J16ebWKU2yagUrer5fBaK"
  },
  "items": {
    "0": {
      "link": "https://arweave.net/flpdtSkJcdospfV93Yfy_tUTrY3abDWDMvTyNMLiY2",
      "name": "TEST 0",
      "onChain": true
    }
  }
}
Yilmaz
  • 35,338
  • 10
  • 157
  • 202