1

So my NFT metadata's collection field is like this:

address: "string"
key: "string",
verified: false

Also the collectionDetails is null.

My question is how to verify the collection and how should I create it that the collectionDetails under nft's metadata has informative props?

2 Answers 2

1

enter image description here

Currently with Metaplex, the recommended approach for grouping a collection by using the mint address of another NFT as the "Collection NFT". The Collection NFT has a collectionDetails field that identifies it as a "sized" collection. This field stores the number of verified NFTs that reference the Collection NFT in their respective collection fields.

https://docs.metaplex.com/programs/token-metadata/certified-collections#collection-nfts

Here is an example of how to use the metaplex sdk to:

  • create a collection NFT

  • create a NFT as part of the collection

  • verify the new NFT as part of the collection

    const connection = new Connection(clusterApiUrl("devnet"))
    
    // Generate a new keypair to use for keypairIdentity
    const keypair = Keypair.generate()
    
    // Fund the keypair with some SOL
    const txSig = await connection.requestAirdrop(
      keypair.publicKey,
      1 * LAMPORTS_PER_SOL
    )
    
    // Confirm airdrop
    const latestBlockHash = await connection.getLatestBlockhash()
    await connection.confirmTransaction(
      {
        blockhash: latestBlockHash.blockhash,
        lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
        signature: txSig,
      },
      "finalized"
    )
    
    // Set up metaplex
    const metaplex = Metaplex.make(connection)
      .use(keypairIdentity(keypair))
      .use(
        bundlrStorage({
          address: "https://devnet.bundlr.network",
          providerUrl: "https://api.devnet.solana.com",
          timeout: 60000,
        })
      )
    
    // convert to metaplex file
    const buffer = fs.readFileSync("src/image.gif")
    const file = toMetaplexFile(buffer, "image.gif")
    
    // upload image
    const imageUri = await metaplex.storage().upload(file)
    console.log("Image URI:", imageUri)
    
    // upload metadata
    const { uri } = await metaplex.nfts().uploadMetadata({
      name: "My NFT",
      description: "My description",
      image: imageUri,
    })
    console.log("Metadata URI:", uri)
    
    // create collection NFT
    const collectionNft = await metaplex.nfts().create(
      {
        uri: uri,
        name: "Collection NFT",
        sellerFeeBasisPoints: 0,
        isCollection: true, // <--- this sets it as a collection NFT
      },
      { commitment: "finalized" }
    )
    // When logged you should see collectionDetails in the nft metadata:
    // "collectionDetails: { version: 'V1', size: <BN: 0> }"
    console.log(collectionNft)
    
    // create NFT in collection
    const nftInCollection = await metaplex.nfts().create(
      {
        uri: uri,
        name: "NFT in Collection",
        sellerFeeBasisPoints: 0,
        collection: collectionNft.mintAddress,
      },
      { commitment: "finalized" }
    )
    
    // verify nft as part of collection
    const verify = await metaplex.nfts().verifyCollection(
      {
        mintAddress: nftInCollection.mintAddress,
        collectionMintAddress: collectionNft.mintAddress,
        isSizedCollection: true,
      },
      { commitment: "finalized" }
    )
    
    // For some reason, "collectionDetails" doesn't show up in the explorers
    console.log(
      `Collection NFT:,
      https://explorer.solana.com/address/${collectionNft.mintAddress.toBase58()}/metadata?cluster=devnet`
    )
    
    // However, the "collection" field in the metadata will be "verified" for the Nft in collection
    console.log(
      `NFT in Collection:,
      https://explorer.solana.com/address/${nftInCollection.mintAddress.toBase58()}/metadata?cluster=devnet`
    )
    
    console.log(
      `Transaction Signature: https://explorer.solana.com/tx/${verify.response.signature}?cluster=devnet`
    )
    

Not sure why, but the collectionDetails field for the Collection NFT does not appear on explorers. However, it is in the NFT metadata when logging it using the Metaplex SDK.

Collection NFT: https://explorer.solana.com/address/4RcsVbzbCMMVpAgnLX1EWgDaHYunRZCYVQTbg6sLzKBd/metadata?cluster=devnet

NFT in Collection: https://explorer.solana.com/address/8H1LLAGv5Ca2xXjhUTmtEYCLBM7vbkPbearVRWr1t2yi/metadata?cluster=devnet

0

I had some problems with the solution code, specially adding the right libraries. Also with metaplex uploading. So I would like to contribute with a full executable code of john and jimi's metadata: Name the script "mint.cjs" Adding also a Devnet funded wallet.

const { Connection, clusterApiUrl, LAMPORTS_PER_SOL, Keypair } = require('@solana/web3.js');
const { Metaplex, keypairIdentity } = require("@metaplex-foundation/js");
const fs = require('fs');


// mint
const mint = async () => {

    const connection = new Connection(clusterApiUrl("devnet"))

    // Generate a new keypair to use for keypairIdentity
    const secret = [6, 75, 114, 41, 237, 21, 146, 239, 34, 199, 207, 63, 78, 73, 16, 187, 113, 38, 228, 73, 244, 253, 210, 84, 197, 26, 247, 50, 181, 61, 184, 221, 208, 236, 132, 116, 6, 84, 36, 102, 26, 230, 69, 156, 226, 121, 29, 12, 240, 33, 123, 145, 229, 194, 213, 51, 46, 233, 45, 36, 106, 221, 171, 221]
    const keypair = Keypair.fromSecretKey(new Uint8Array(secret));

    // Set up metaplex
    const metaplex = Metaplex.make(connection)
        .use(keypairIdentity(keypair))

    // urls
    const metadataUri = "https://raw.githubusercontent.com/687c/solana-nft-native-client/main/metadata.json"

    // create collection NFT
    const collectionNft = await metaplex.nfts().create(
        {
            uri: metadataUri,
            name: "Collection NFT",
            sellerFeeBasisPoints: 0,
            isCollection: true, // <--- this sets it as a collection NFT
        },
        { commitment: "finalized" }
    )
    // When logged you should see collectionDetails in the nft metadata:
    // "collectionDetails: { version: 'V1', size: <BN: 0> }"
    console.log(collectionNft)

    // create NFT in collection
    const nftInCollection = await metaplex.nfts().create(
        {
            uri: metadataUri,
            name: "NFT in Collection",
            sellerFeeBasisPoints: 0,
            collection: collectionNft.mintAddress,
        },
        { commitment: "finalized" }
    )

    // verify nft as part of collection
    const verify = await metaplex.nfts().verifyCollection(
        {
            mintAddress: nftInCollection.mintAddress,
            collectionMintAddress: collectionNft.mintAddress,
            isSizedCollection: true,
        },
        { commitment: "finalized" }
    )

    // For some reason, "collectionDetails" doesn't show up in the explorers
    console.log(
        `Collection NFT:,
    https://explorer.solana.com/address/${collectionNft.mintAddress.toBase58()}/metadata?cluster=devnet`
    )

    // However, the "collection" field in the metadata will be "verified" for the Nft in collection
    console.log(
        `NFT in Collection:,
    https://explorer.solana.com/address/${nftInCollection.mintAddress.toBase58()}/metadata?cluster=devnet`
    )

    console.log(
        `Transaction Signature: https://explorer.solana.com/tx/${verify.response.signature}?cluster=devnet`
    )

}


// mint
mint()
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.