Mint NFT
v1 toke metadata + v1 master edition
import { Keypair, Connection, PublicKey, Transaction, SystemProgram } from "@solana/web3.js";
import base58 from "bs58";
import {
createAssociatedTokenAccountInstruction,
createInitializeMintInstruction,
createMintToCheckedInstruction,
getAssociatedTokenAddress,
getMinimumBalanceForRentExemptMint,
MINT_SIZE,
TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
import {
PROGRAM_ID as MPL_TOKEN_METADATA_PROGRAM_ID,
createCreateMetadataAccountInstruction,
createCreateMasterEditionInstruction,
} from "@metaplex-foundation/mpl-token-metadata";
let connection = new Connection("https://api.devnet.solana.com");
// 5pVyoAeURQHNMVU7DmfMHvCDNmTEYXWfEwc136GYhTKG
const feePayer = Keypair.fromSecretKey(
base58.decode("5MaiiCavjCmn9Hs1o3eznqDEhRwxo7pXiAYez7keQUviUkauRiTMD8DrESdrNjN8zd9mTmVhRvBJeg5vhyvgrAhG")
);
(async () => {
let mint = Keypair.generate();
console.log(`mint: ${mint.publicKey.toBase58()}`);
let ata = await getAssociatedTokenAddress(mint.publicKey, feePayer.publicKey);
let tokenMetadataPubkey = await getMetadataPDA(mint.publicKey);
let masterEditionPubkey = await getMasterEditionPDA(mint.publicKey);
let tx = new Transaction().add(
SystemProgram.createAccount({
fromPubkey: feePayer.publicKey,
newAccountPubkey: mint.publicKey,
lamports: await getMinimumBalanceForRentExemptMint(connection),
space: MINT_SIZE,
programId: TOKEN_PROGRAM_ID,
}),
createInitializeMintInstruction(mint.publicKey, 0, feePayer.publicKey, feePayer.publicKey),
createAssociatedTokenAccountInstruction(feePayer.publicKey, ata, feePayer.publicKey, mint.publicKey),
createMintToCheckedInstruction(mint.publicKey, ata, feePayer.publicKey, 1, 0),
createCreateMetadataAccountInstruction(
{
metadata: tokenMetadataPubkey,
mint: mint.publicKey,
mintAuthority: feePayer.publicKey,
payer: feePayer.publicKey,
updateAuthority: feePayer.publicKey,
},
{
createMetadataAccountArgs: {
data: {
name: "Fake SMS #1355",
symbol: "FSMB",
uri: "https://34c7ef24f4v2aejh75xhxy5z6ars4xv47gpsdrei6fiowptk2nqq.arweave.net/3wXyF1wvK6ARJ_9ue-O58CMuXrz5nyHEiPFQ6z5q02E",
sellerFeeBasisPoints: 100,
creators: [
{
address: feePayer.publicKey,
verified: true,
share: 100,
},
],
},
isMutable: true,
},
}
),
createCreateMasterEditionInstruction(
{
edition: masterEditionPubkey,
mint: mint.publicKey,
updateAuthority: feePayer.publicKey,
mintAuthority: feePayer.publicKey,
payer: feePayer.publicKey,
metadata: tokenMetadataPubkey,
},
{
createMasterEditionArgs: {
maxSupply: 0,
},
}
)
);
console.log(await connection.sendTransaction(tx, [feePayer, mint]));
})();
async function getMetadataPDA(mint: PublicKey): Promise<PublicKey> {
const [publicKey] = await PublicKey.findProgramAddress(
[Buffer.from("metadata"), MPL_TOKEN_METADATA_PROGRAM_ID.toBuffer(), mint.toBuffer()],
MPL_TOKEN_METADATA_PROGRAM_ID
);
return publicKey;
}
async function getMasterEditionPDA(mint: PublicKey): Promise<PublicKey> {
const [publicKey] = await PublicKey.findProgramAddress(
[Buffer.from("metadata"), MPL_TOKEN_METADATA_PROGRAM_ID.toBuffer(), mint.toBuffer(), Buffer.from("edition")],
MPL_TOKEN_METADATA_PROGRAM_ID
);
return publicKey;
}
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
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
v2 token metadata + v3 master edition
import { Keypair, Connection, PublicKey, Transaction, SystemProgram } from "@solana/web3.js";
import base58 from "bs58";
import {
createAssociatedTokenAccountInstruction,
createInitializeMintInstruction,
createMintToCheckedInstruction,
getAssociatedTokenAddress,
getMinimumBalanceForRentExemptMint,
MINT_SIZE,
TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
import {
PROGRAM_ID as MPL_TOKEN_METADATA_PROGRAM_ID,
createCreateMetadataAccountV2Instruction,
createCreateMasterEditionV3Instruction,
} from "@metaplex-foundation/mpl-token-metadata";
let connection = new Connection("https://api.devnet.solana.com");
// 5pVyoAeURQHNMVU7DmfMHvCDNmTEYXWfEwc136GYhTKG
const feePayer = Keypair.fromSecretKey(
base58.decode("5MaiiCavjCmn9Hs1o3eznqDEhRwxo7pXiAYez7keQUviUkauRiTMD8DrESdrNjN8zd9mTmVhRvBJeg5vhyvgrAhG")
);
(async () => {
let mint = Keypair.generate();
console.log(`mint: ${mint.publicKey.toBase58()}`);
let ata = await getAssociatedTokenAddress(mint.publicKey, feePayer.publicKey);
let tokenMetadataPubkey = await getMetadataPDA(mint.publicKey);
let masterEditionPubkey = await getMasterEditionPDA(mint.publicKey);
let tx = new Transaction().add(
SystemProgram.createAccount({
fromPubkey: feePayer.publicKey,
newAccountPubkey: mint.publicKey,
lamports: await getMinimumBalanceForRentExemptMint(connection),
space: MINT_SIZE,
programId: TOKEN_PROGRAM_ID,
}),
createInitializeMintInstruction(mint.publicKey, 0, feePayer.publicKey, feePayer.publicKey),
createAssociatedTokenAccountInstruction(feePayer.publicKey, ata, feePayer.publicKey, mint.publicKey),
createMintToCheckedInstruction(mint.publicKey, ata, feePayer.publicKey, 1, 0),
createCreateMetadataAccountV2Instruction(
{
metadata: tokenMetadataPubkey,
mint: mint.publicKey,
mintAuthority: feePayer.publicKey,
payer: feePayer.publicKey,
updateAuthority: feePayer.publicKey,
},
{
createMetadataAccountArgsV2: {
data: {
name: "Fake SMS #1355",
symbol: "FSMB",
uri: "https://34c7ef24f4v2aejh75xhxy5z6ars4xv47gpsdrei6fiowptk2nqq.arweave.net/3wXyF1wvK6ARJ_9ue-O58CMuXrz5nyHEiPFQ6z5q02E",
sellerFeeBasisPoints: 100,
creators: [
{
address: feePayer.publicKey,
verified: true,
share: 100,
},
],
collection: null,
uses: null,
},
isMutable: true,
},
}
),
createCreateMasterEditionV3Instruction(
{
edition: masterEditionPubkey,
mint: mint.publicKey,
updateAuthority: feePayer.publicKey,
mintAuthority: feePayer.publicKey,
payer: feePayer.publicKey,
metadata: tokenMetadataPubkey,
},
{
createMasterEditionArgs: {
maxSupply: 0,
},
}
)
);
console.log(await connection.sendTransaction(tx, [feePayer, mint]));
})();
async function getMetadataPDA(mint: PublicKey): Promise<PublicKey> {
const [publicKey] = await PublicKey.findProgramAddress(
[Buffer.from("metadata"), MPL_TOKEN_METADATA_PROGRAM_ID.toBuffer(), mint.toBuffer()],
MPL_TOKEN_METADATA_PROGRAM_ID
);
return publicKey;
}
async function getMasterEditionPDA(mint: PublicKey): Promise<PublicKey> {
const [publicKey] = await PublicKey.findProgramAddress(
[Buffer.from("metadata"), MPL_TOKEN_METADATA_PROGRAM_ID.toBuffer(), mint.toBuffer(), Buffer.from("edition")],
MPL_TOKEN_METADATA_PROGRAM_ID
);
return publicKey;
}
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
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