-
Notifications
You must be signed in to change notification settings - Fork 166
/
6.createNFTs.ts
110 lines (83 loc) · 3.47 KB
/
6.createNFTs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Demonstrates how to mint NFTs and store their metadata on chain using the Metaplex MetadataProgram
*/
// import custom helpers for demos
import { payer, connection } from "@/lib/vars";
import { explorerURL, loadPublicKeysFromFile, printConsoleSeparator } from "@/lib/helpers";
import { PublicKey } from "@solana/web3.js";
import { Metaplex, bundlrStorage, keypairIdentity } from "@metaplex-foundation/js";
(async () => {
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
console.log("Payer address:", payer.publicKey.toBase58());
//////////////////////////////////////////////////////////////////////////////
// load the stored PublicKeys for ease of use
let localKeys = loadPublicKeysFromFile();
// ensure the desired script was already run
if (!localKeys?.tokenMint)
return console.warn("No local keys were found. Please run '3.createTokenWithMetadata.ts'");
const tokenMint: PublicKey = localKeys.tokenMint;
console.log("==== Local PublicKeys loaded ====");
console.log("Token's mint address:", tokenMint.toBase58());
console.log(explorerURL({ address: tokenMint.toBase58() }));
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* define our ship's JSON metadata
* checkout: https://nft.storage/ to help store images
*/
const metadata = {
name: "The Gradient Pearl",
symbol: "SHIP",
description:
"The Gradient Pearl is a legendary Pirate ship that sails the Seven Seas. Captain Rajovenko leads with a drink can in his hand. ",
image:
"https://bafybeic75qqhfytc6xxoze2lo5af2lfhmo2kh4mhirelni2wota633dgqu.ipfs.nftstorage.link/",
};
// another ship: "https://bafybeiblld2wlxyivlivnhaqbcixhzxrodjzrycjkitz3kdmzj65gebwxe.ipfs.nftstorage.link/"
// Captain Rajovenko: "https://bafybeihww4tue5pme3h2udqvkpfbzs5zf4h2pysuoowwofbbk372vvtmja.ipfs.nftstorage.link/"
/**
* Use the Metaplex sdk to handle most NFT actions
*/
// create an instance of Metaplex sdk for use
const metaplex = Metaplex.make(connection)
// set our keypair to use, and pay for the transaction
.use(keypairIdentity(payer))
// define a storage mechanism to upload with
.use(
bundlrStorage({
address: "https://devnet.bundlr.network",
providerUrl: "https://api.devnet.solana.com",
timeout: 60000,
}),
);
console.log("Uploading metadata...");
// upload the JSON metadata
const { uri } = await metaplex.nfts().uploadMetadata(metadata);
console.log("Metadata uploaded:", uri);
printConsoleSeparator("NFT details");
console.log("Creating NFT using Metaplex...");
// create a new nft using the metaplex sdk
const { nft, response } = await metaplex.nfts().create({
uri,
name: metadata.name,
symbol: metadata.symbol,
// `sellerFeeBasisPoints` is the royalty that you can define on nft
sellerFeeBasisPoints: 500, // Represents 5.00%.
//
isMutable: true,
});
console.log(nft);
printConsoleSeparator("NFT created:");
console.log(explorerURL({ txSignature: response.signature }));
return;
/**
*
*/
printConsoleSeparator("Find by mint:");
// you can also use the metaplex sdk to retrieve info about the NFT's mint
const mintInfo = await metaplex.nfts().findByMint({
mintAddress: tokenMint,
});
console.log(mintInfo);
})();