diff --git a/project-6-nfts/create-collection.ts b/project-6-nfts/create-collection.ts index 18ab5b3..c8eef4c 100644 --- a/project-6-nfts/create-collection.ts +++ b/project-6-nfts/create-collection.ts @@ -12,55 +12,65 @@ import { import { createUmi } from "@metaplex-foundation/umi-bundle-defaults"; -import { Connection, LAMPORTS_PER_SOL, clusterApiUrl } from "@solana/web3.js"; +import { Connection, PublicKey, LAMPORTS_PER_SOL, clusterApiUrl } from "@solana/web3.js"; import { generateSigner, keypairIdentity, percentAmount, } from "@metaplex-foundation/umi"; +import { createMint } from "@solana/spl-token"; -const connection = new Connection(clusterApiUrl("devnet")); -const user = await getKeypairFromFile(); +async function NewCreateNFT() { -await airdropIfRequired( - connection, - user.publicKey, - 1 * LAMPORTS_PER_SOL, - 0.5 * LAMPORTS_PER_SOL -); + const connection = new Connection(clusterApiUrl("devnet")); -console.log("Loaded user", user.publicKey.toBase58()); + const user = await getKeypairFromFile(); -const umi = createUmi(connection.rpcEndpoint); -umi.use(mplTokenMetadata()); + await airdropIfRequired( + connection, + user.publicKey, + 1 * LAMPORTS_PER_SOL, + 0.5 * LAMPORTS_PER_SOL + ); -const umiUser = umi.eddsa.createKeypairFromSecretKey(user.secretKey); -umi.use(keypairIdentity(umiUser)); + console.log("Loaded user", user.publicKey.toBase58()); -console.log("Set up Umi instance for user"); + const umi = createUmi(connection.rpcEndpoint); + umi.use(mplTokenMetadata()); -const collectionMint = generateSigner(umi); + const umiUser = umi.eddsa.createKeypairFromSecretKey(user.secretKey); + umi.use(keypairIdentity(umiUser)); -const transaction = await createNft(umi, { - mint: collectionMint, - name: "My Collection", - symbol: "MC", - uri: "https://raw.githubusercontent.com/solana-developers/professional-education/main/labs/sample-nft-collection-offchain-data.json", - sellerFeeBasisPoints: percentAmount(0), - isCollection: true, -}); -await transaction.sendAndConfirm(umi); + console.log("Set up Umi instance for user"); -const createdCollectionNft = await fetchDigitalAsset( - umi, - collectionMint.publicKey -); + const collectionMint = generateSigner(umi); -console.log( - `Created Collection 📦! Address is ${getExplorerLink( - "address", - createdCollectionNft.mint.publicKey, - "devnet" - )}` -); + const collectionMintPubKey = new PublicKey(collectionMint.publicKey); + + await createMint(connection, user, collectionMintPubKey, null, 0); + + const transaction = await createNft(umi, { + mint: collectionMint, + name: "My Collection", + symbol: "MC", + uri: "https://raw.githubusercontent.com/solana-developers/professional-education/main/labs/sample-nft-collection-offchain-data.json", + sellerFeeBasisPoints: percentAmount(0), + isCollection: true, + }); + await transaction.sendAndConfirm(umi); + + const createdCollectionNft = await fetchDigitalAsset( + umi, + collectionMint.publicKey + ); + + console.log( + `Created Collection 📦! Address is ${getExplorerLink( + "address", + createdCollectionNft.mint.publicKey, + "devnet" + )}` + ); + +} \ No newline at end of file