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()