-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_createNFTCollection.ts
129 lines (102 loc) · 3.16 KB
/
1_createNFTCollection.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import dotenv from 'dotenv';
dotenv.config();
import * as fs from 'fs';
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import {
mplTokenMetadata,
createNft,
} from '@metaplex-foundation/mpl-token-metadata';
import {
generateSigner,
percentAmount,
createGenericFile,
signerIdentity,
createSignerFromKeypair,
} from '@metaplex-foundation/umi';
import {
COLLECTION_NAME,
COLLECTION_SYMBOL,
COLLECTION_DESCRIPTION,
FEE_PERCENT,
EXTERNAL_URL,
METADATA_COLLECTION_URL,
IMAGE_URL,
} from './config';
import {
addrToLink
} from './utils';
const rpcURL =
(process.env.NODE_ENV === 'production'
? process.env.SOLANA_MAINNET_RPC_URL
: process.env.SOLANA_DEVNET_RPC_URL) || 'https://api.devnet.solana.com';
const payerKeyFile = 'key.json';
const keyData = fs.readFileSync(payerKeyFile, 'utf8');
const secretKey = new Uint8Array(JSON.parse(keyData));
const run = async () => {
try {
const umi = createUmi(rpcURL)
.use(mplTokenMetadata())
const keyPair = umi.eddsa.createKeypairFromSecretKey(secretKey);
const signer = createSignerFromKeypair(
{ eddsa: umi.eddsa },
keyPair
);
umi.use(signerIdentity(signer));
// return;
const collectionImageUri = IMAGE_URL;
fs.writeFileSync(
'./data/collectionImageUri.txt',
collectionImageUri
);
const collectionObject = {
name : COLLECTION_NAME,
symbol : COLLECTION_SYMBOL,
description : COLLECTION_DESCRIPTION,
seller_fee_basis_points: FEE_PERCENT * 100,
image : collectionImageUri,
external_url : EXTERNAL_URL,
properties : {
category: 'image',
files: [
{
file: collectionImageUri,
type: 'image/png',
},
],
},
};
const collectionJsonUri = METADATA_COLLECTION_URL;
console.log('collectionJsonUri:', collectionJsonUri);
fs.writeFileSync(
'./data/collectionJsonUri.txt',
collectionJsonUri
);
const collectionMint = generateSigner(umi);
console.log("collectionMint:", collectionMint.publicKey);
//return;
await createNft(umi, {
mint : collectionMint,
symbol : COLLECTION_SYMBOL,
name : COLLECTION_NAME,
uri : collectionJsonUri,
sellerFeeBasisPoints: percentAmount(FEE_PERCENT),
isCollection : true,
}).sendAndConfirm(umi);
const collectionMintExplolerUrl = `https://explorer.solana.com/address/${
collectionMint.publicKey
}${process.env.NODE_ENV !== 'production' && '?cluster=devnet'}`
console.log('collectionMint:', collectionMintExplolerUrl);
let cluster = ""; if (process.env.NODE_ENV !== 'production') { cluster = '?cluster=devnet';}
const txLink = addrToLink( collectionMint.publicKey, cluster);
console.log(txLink);
fs.writeFileSync(
`./data/collectionMint${
process.env.NODE_ENV === 'production' ? 'Mainnet' : 'Devnet'
}.txt`,
collectionMint.publicKey
);
} catch (e) {
console.error(e);
}
}
void run();