Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 46 additions & 36 deletions project-6-nfts/create-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)}`
);

}