-
Notifications
You must be signed in to change notification settings - Fork 5
/
gacha-cli.mjs
717 lines (647 loc) · 24.4 KB
/
gacha-cli.mjs
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
import { program } from 'commander';
import * as path from 'path';
import * as fs from 'fs';
import Caver from "caver-js";
import pinFileToIPFS from './ipfsUpload.mjs';
import awsUpload from './awsUpload.mjs';
const CACHE_PATH = './.cache/info.json';
const CONFIG_PATH = './config.json';
const CONTRACT_PATH = './Contract.json';
const WHITELIST_PATH = './whiteList.json';
const TRANSFER_PATH = './transferList.json';
const WL_CACHE = './src/Constant/whiteList.json';
const contractBuffer = fs.readFileSync(CONTRACT_PATH);
const contractJson = contractBuffer.toString();
const contractData = JSON.parse(contractJson);
let gachaAddress = contractData.gachaAddress;
let gachaABI = contractData.gachaABI;
program.version('0.0.2');
program.command('verify')
.requiredOption(
'-n, --network <string>',
'JSON file with gacha machine settings',
)
.action(async (options) => {
let ret;
let rpcURL;
const configBuffer = fs.readFileSync(CONFIG_PATH);
const configJson = configBuffer.toString();
const configData = JSON.parse(configJson);
let caver;
let contract;
if(options.network == 'baobab'){
rpcURL = contractData.baobabRPCURL;
caver = new Caver(rpcURL);
gachaAddress = contractData.gachaAddressBaobab;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else if(options.network == 'mainnet'){
rpcURL = contractData.mainnetRPCURL;
caver = new Caver(rpcURL);
contract = await caver.contract.create(gachaABI, gachaAddress);
}else{
throw new Error(
'The Network name is wrong. 네트워크명은 baobab이나 mainnet으로 입력 바랍니다.',
);
}
const minterAddress = configData.TreasuryAccount;
const minterPrivateKey = configData.PrivateKey;
const mintNum = configData.NumberOfNFT;
ret = await caver.klay.accounts.createWithAccountKey(minterAddress, minterPrivateKey);
ret = caver.klay.accounts.wallet.add(ret);
ret = caver.klay.accounts.wallet.getAccount(0);
const cacheBuffer = fs.readFileSync(CACHE_PATH);
const cacheJSON = cacheBuffer.toString();
const cacheData = JSON.parse(cacheJSON);
let flag = true;
let tempArr = new Array();
let uriCnt = 0;
for(var i = 0;i<cacheData.items.length;i++){
tempArr.push(cacheData.items[i].link);
uriCnt++;
if((uriCnt)%100 == 0 || i == (cacheData.items.length-1)){
ret = await contract.methods.getUploaded(minterAddress,(i+1-uriCnt),uriCnt, tempArr).call();
for(var j = 0;j<uriCnt;j++){
if(ret[j].toString() == "true"){
console.log("Uploaded number " + j + ": on chain");
cacheData.items[j].onChain = "true";
}else{
console.log("Uploaded number " + j + ": it's NOT on chain");
cacheData.items[j].onChain = "false";
flag = false;
}
}
uriCnt = 0;
tempArr = [];
}
// ret = await wait(1500);
}
if(!flag){
console.log("Some of uploaded are NOT on chain. Please upload again.");
}else{
console.log("All uploaded are successfully on chain.");
}
fs.writeFileSync(CACHE_PATH, JSON.stringify(cacheData));
});
program
.command('upload')
.argument(
'<directory>',
'Directory containing images named from 0-n',
val => {
return fs.readdirSync(`${val}`).map(file => path.join(val, file));
},
)
.requiredOption(
'-n, --network <string>',
'JSON file with gacha machine settings',
)
.option(
'-i, --ipfs',
'Upload image files to pinata ipfs if you need',
)
.option(
'-a, --aws',
'Upload image files and json files to aws s3',
)
.action(async (files, options, cmd) => {
const dirName = cmd.args[0];
console.log(options);
let rpcURL;
let ret;
let contract;
const configBuffer = fs.readFileSync('./config.json');
const configJson = configBuffer.toString();
const configData = JSON.parse(configJson);
const imageExtension = configData.imageExtension;
let caver;
let nftContract;
if(options.network == 'baobab'){
rpcURL = contractData.baobabRPCURL;
caver = await new Caver(rpcURL);
gachaAddress = contractData.gachaAddressBaobab;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else if(options.network == 'mainnet'){
rpcURL = contractData.mainnetRPCURL;
caver = await new Caver(rpcURL);
gachaAddress = contractData.gachaAddress;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else{
throw new Error(
'The Network name is wrong. 네트워크명은 baobab이나 mainnet으로 입력 바랍니다.',
);
}
const minterAddress = configData.TreasuryAccount;
const minterPrivateKey = configData.PrivateKey;
const tokenName = configData.TokenName;
const tokenSymbol = configData.TokenSymbol;
ret = caver.klay.accounts.createWithAccountKey(minterAddress, minterPrivateKey);
ret = caver.klay.accounts.wallet.add(ret);
ret = caver.klay.accounts.wallet.getAccount(0);
// Set connection with IPFS Node
caver.ipfs.setIPFSNode('ipfs.infura.io', 5001, true);
const imageFiles = files.filter(it => {
return !it.endsWith('.json');
});
const imageFileCount = imageFiles.length;
const jsonFileCount = files.filter(it => {
return it.endsWith('.json');
}).length;
if(options.ipfs || options.aws){
if (imageFileCount !== jsonFileCount) {
throw new Error(
`number of image files (${imageFileCount}) is different than the number of json files (${jsonFileCount}). 이미지 파일과 json 파일의 숫자가 다릅니다.`,
);
}
}
const totalCnt = configData.NumberOfNFT;
console.log("total", totalCnt);
let cacheData = '';
let cacheCnt = 0;
var uriCnt = 0;
let uriMetaForUpload = new Array();
var items = new Array();
let uploadedCnt = 0;
let uploadedCntFlag = 0;
if(!fs.existsSync('./.cache')){
fs.mkdirSync('./.cache');
ret = await caver.klay.sendTransaction({
type: 'SMART_CONTRACT_EXECUTION',
from: minterAddress,
to: gachaAddress,
data: contract.methods.mintNewToken(tokenName, tokenSymbol,totalCnt).encodeABI(),
gas: '5000000'
}).then(console.log("New collection is successfully made."));
nftContract = ret.logs[0].address;
console.log("NFT contract address is ", ret.logs[0].address);
}else if(fs.existsSync('./.cache/info.json')){
const cacheBuffer = fs.readFileSync(CACHE_PATH);
const cacheJson = cacheBuffer.toString();
const dataCache = JSON.parse(cacheJson);
nftContract = dataCache.NFTContract;
if(dataCache.gachaMachineId != minterAddress || configData.TokenName != dataCache.tokenName){
throw new Error(
'The ./cache/info.json file is not match with minter address. ./cache/info.json 파일을 확인하시고, 필요하지 않다면 해당 파일을 삭제해주세요.',
);
}
for(let j = 0;j<dataCache.items.length;j++){
if(dataCache.items[j].onChain == "false"){
uploadedCnt = j;
uploadedCntFlag = 1;
break;
}else{
items.push(dataCache.items[j]);
}
}
if(uploadedCntFlag == 1){
for(let j = uploadedCnt;j<dataCache.items.length;j++){
const metadata = dirName + '/' + j + '.json';
const dataBuffer = fs.readFileSync(metadata);
const dataJson = dataBuffer.toString();
const metadataJson = JSON.parse(dataJson);
console.log("Number : " + j + " upload again...");
let cidMeta;
let uriMeta;
let uriLength;
if(options.aws){
cidMeta = await awsUpload(metadata, "json");
uriMeta = cidMeta;
}else if(options.ipfs){
cidMeta = await pinFileToIPFS(metadata);
uriMeta = "ipfs://" + cidMeta;
}else{
if(configData.pinataApiKey.length > 0){
cidMeta = await pinFileToIPFS(metadata);
uriMeta = "ipfs://" + cidMeta;
}else if(configData.awsAccessKey.length > 0){
cidMeta = await awsUpload(metadata, "json");
uriMeta = cidMeta;
}
}
uriMetaForUpload.push(uriMeta);
}
ret = await caver.klay.sendTransaction({
type: 'SMART_CONTRACT_EXECUTION',
from: minterAddress,
to: gachaAddress,
data: contract.methods.uploadBulk(totalCnt, j, uriMetaForUpload,(dataCache.items.length-uploadedCnt)).encodeABI(),
gas: '1000000'
});
ret = await contract.methods.getUploaded(minterAddress,uploadedCnt,(dataCache.items.length-uploadedCnt), uriMetaForUpload).call();
for(let j = 0;j<(dataCache.items.length-uploadedCnt);j++){
if(ret[j].toString() == "true"){
console.log("Uploaded number " + (j + uploadedCnt) + ": on chain");
items.push({
"id" : j + uploadedCnt,
"link" : uriMeta,
"name" : metadataJson.name,
"onChain" : "true"
});
}else{
console.log("Uploaded number " + j + ": is still not on chain");
items.push({
"id" : j + uploadedCnt,
"link" : uriMeta,
"name" : metadataJson.name,
"onChain" : "false"
});
}
}
}
cacheData = {
"tokenName" : configData.TokenName,
"gachaMachineId" : minterAddress,
"items" : items,
"NFTContract" : nftContract
}
fs.writeFileSync(CACHE_PATH, JSON.stringify(cacheData));
console.log("Start to upload from " + dataCache.items.length + "...");
uriCnt = 0;
cacheCnt = dataCache.items.length;
uriMetaForUpload = [];
}else{
ret = await caver.klay.sendTransaction({
type: 'SMART_CONTRACT_EXECUTION',
from: minterAddress,
to: gachaAddress,
data: contract.methods.mintNewToken(tokenName, tokenSymbol,totalCnt).encodeABI(),
gas: '5000000'
}).then(console.log("New collection is successfully made."));
nftContract = ret.logs[0].address;
console.log("NFT contract address is ", ret.logs[0].address);
}
for(let i = cacheCnt;i<totalCnt;i++){
const metadata = dirName + '/' + i + '.json';
const dataBuffer = fs.readFileSync(metadata);
const dataJson = dataBuffer.toString();
const metadataJson = JSON.parse(dataJson);
console.log("Number : ", i);
uriCnt++;
if(options.ipfs){
const image = dirName + '/' + i + '.' + imageExtension;
const cidImage = await pinFileToIPFS(image);
// Add a file to IPFS with file path
const uriImage = "https://ipfs.io/ipfs/" + cidImage;
metadataJson.image = uriImage;
fs.writeFileSync(metadata.toString(), JSON.stringify(metadataJson));
}else if(options.aws){
const image = dirName + '/' + i + '.' + imageExtension;
const cidImage = await awsUpload(image, imageExtension);
// Add a file to AWSS3 with file path
const uriImage = cidImage;
metadataJson.image = uriImage;
fs.writeFileSync(metadata.toString(), JSON.stringify(metadataJson));
}
let cidMeta;
let uriMeta;
let uriLength;
if(options.aws){
cidMeta = await awsUpload(metadata, "json");
uriMeta = cidMeta;
uriMetaForUpload.push(uriMeta);
}else if(options.ipfs){
cidMeta = await pinFileToIPFS(metadata);
uriMeta = "ipfs://" + cidMeta;
uriMetaForUpload.push(uriMeta);
}else{
if(configData.pinataApiKey.length > 0){
cidMeta = await pinFileToIPFS(metadata);
uriMeta = "ipfs://" + cidMeta;
uriMetaForUpload.push(uriMeta);
}else if(configData.awsAccessKey.length > 0){
cidMeta = await awsUpload(metadata, "json");
uriMeta = cidMeta;
uriMetaForUpload.push(uriMeta);
}
}
items.push({
"id" : i,
"link" : uriMeta,
"name" : metadataJson.name,
"onChain" : "false"
});
if(((i+1)%10) == 0 || i == (totalCnt-1)){
if(uriCnt == 10){
console.log("Upload " + (i-9) + "-" + (i));
}else{
console.log("Upload ~ " + (i));
}
cacheData = {
"tokenName" : configData.TokenName,
"gachaMachineId" : minterAddress,
"items" : items,
"NFTContract" : nftContract
}
ret = await caver.klay.sendTransaction({
type: 'SMART_CONTRACT_EXECUTION',
from: minterAddress,
to: gachaAddress,
data: contract.methods.uploadBulk(totalCnt, i, uriMetaForUpload, uriCnt).encodeABI(),
gas: '1000000'
})
fs.writeFileSync(CACHE_PATH, JSON.stringify(cacheData));
uriCnt = 0;
uriMetaForUpload = [];
}
}
});
program
.command('applyWhiteList')
.action(async () => {
let ret;
let rpcURL = contractData.baobabRPCURL;
let caver = await new Caver(rpcURL);
const configBuffer = fs.readFileSync('./config.json');
const configJson = configBuffer.toString();
const configData = JSON.parse(configJson);
caver.ipfs.setIPFSNode('ipfs.infura.io', 5001, true);
const WLHash = await caver.ipfs.add(WHITELIST_PATH);
console.log(WLHash);
const WL_json = JSON.parse('{"whiteList" : "https://ipfs.io/ipfs/' + WLHash + '"}');
fs.writeFileSync(WL_CACHE, JSON.stringify(WL_json));
});
program
.command('mintToken')
.argument(
'<number>',
'Number of NFTs you want to mint',
)
.requiredOption(
'-n, --network <string>',
'JSON file with gacha machine settings',
)
.action(async (files, options, cmd) => {
const mintNum = cmd.args[0];
console.log(options);
let rpcURL;
let ret;
let contract;
const configBuffer = fs.readFileSync('./config.json');
const configJson = configBuffer.toString();
const configData = JSON.parse(configJson);
const imageExtension = configData.imageExtension;
let caver;
let gaslimit = mintNum * 850000;
if(options.network == 'baobab'){
rpcURL = contractData.baobabRPCURL;
caver = await new Caver(rpcURL);
gachaAddress = contractData.gachaAddressBaobab;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else if(options.network == 'mainnet'){
rpcURL = contractData.mainnetRPCURL;
caver = await new Caver(rpcURL);
contract = await caver.contract.create(gachaABI, gachaAddress);
}else{
throw new Error(
'The Network name is wrong. 네트워크명은 baobab이나 mainnet으로 입력 바랍니다.',
);
}
const minterAddress = configData.TreasuryAccount;
const minterPrivateKey = configData.PrivateKey;
const tokenName = configData.TokenName;
const tokenSymbol = configData.TokenSymbol;
ret = caver.klay.accounts.createWithAccountKey(minterAddress, minterPrivateKey);
ret = caver.klay.accounts.wallet.add(ret);
ret = caver.klay.accounts.wallet.getAccount(0);
let mintCount = await contract.methods.getMintedCount(minterAddress).call();
ret = await caver.klay.sendTransaction({
type: 'SMART_CONTRACT_EXECUTION',
from: minterAddress,
to: gachaAddress,
value: caver.utils.toPeb((0.11 * mintNum).toString(), 'KLAY'),
data: contract.methods.mint(minterAddress,mintNum, minterAddress).encodeABI(),
gas: gaslimit
}).then(async (res)=>{
console.log("Mint has succeded");
mintCount = await contract.methods.getMintedCount(minterAddress).call();
console.log("You've minted " + mintCount + " of NFTs");
})
.catch((err) => {
console.log(err);
console.log("Mint has failed.");});
});
program
.command('multiTransfer')
.requiredOption(
'-n, --network <string>',
'JSON file with gacha machine settings',
)
.action(async (options, cmd) => {
console.log(options);
let rpcURL;
let ret;
let contract;
const configBuffer = fs.readFileSync('./config.json');
const configJson = configBuffer.toString();
const configData = JSON.parse(configJson);
let caver;
const cacheBuffer = fs.readFileSync(CACHE_PATH);
const cacheJSON = cacheBuffer.toString();
const cacheData = JSON.parse(cacheJSON);
if(options.network == 'baobab'){
rpcURL = contractData.baobabRPCURL;
caver = await new Caver(rpcURL);
}else if(options.network == 'mainnet'){
rpcURL = contractData.mainnetRPCURL;
caver = await new Caver(rpcURL);
}else{
throw new Error(
'The Network name is wrong. 네트워크명은 baobab이나 mainnet으로 입력 바랍니다.',
);
}
const minterAddress = configData.TreasuryAccount;
const minterPrivateKey = configData.PrivateKey;
ret = caver.klay.accounts.createWithAccountKey(minterAddress, minterPrivateKey);
ret = caver.klay.accounts.wallet.add(ret);
ret = caver.klay.accounts.wallet.getAccount(0);
const trListBuffer = fs.readFileSync(TRANSFER_PATH);
const trListJson = trListBuffer.toString();
const trListData = JSON.parse(trListJson);
const kip17Instance = await new caver.klay.KIP17(cacheData.NFTContract);
let startTokenId = trListData.startTokenId;
for(let i = 0; i<trListData.items.length;i++){
console.log("address : ", trListData.items[i].address);
for(let j = 0;j<trListData.items[i].tokenNum;j++){
ret = await kip17Instance.safeTransferFrom(minterAddress, trListData.items[i].address.toString(), startTokenId, {
from : minterAddress,
gas: '1000000'
}).then((res) => {
console.log("Number " + startTokenId + " has sent.");
startTokenId++;
})
.catch((err) => {
console.log(err);
console.log("Transfer has failed.");
console.log("가스비가 모자라거나, 소유하지 않은 NFT일 수 있습니다. 이외에 Transfer가 끊긴 경우, 현재까지 진행된 Transfer 리스트를 transferList.json에서 삭제하시고 재실행해보시길 바랍니다.");
});
}
}
});
program
.command('getMintCnt')
.requiredOption(
'-n, --network <string>',
'JSON file with gacha machine settings',
)
.action(async (options) => {
let rpcURL;
let ret;
let contract;
const configBuffer = fs.readFileSync('./config.json');
const configJson = configBuffer.toString();
const configData = JSON.parse(configJson);
const imageExtension = configData.imageExtension;
let caver;
if(options.network == 'baobab'){
rpcURL = contractData.baobabRPCURL;
caver = await new Caver(rpcURL);
gachaAddress = contractData.gachaAddressBaobab;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else if(options.network == 'mainnet'){
rpcURL = contractData.mainnetRPCURL;
caver = await new Caver(rpcURL);
contract = await caver.contract.create(gachaABI, gachaAddress);
}else{
throw new Error(
'The Network name is wrong. 네트워크명은 baobab이나 mainnet으로 입력 바랍니다.',
);
}
const minterAddress = configData.TreasuryAccount;
const minterPrivateKey = configData.PrivateKey;
const tokenName = configData.TokenName;
const tokenSymbol = configData.TokenSymbol;
ret = caver.klay.accounts.createWithAccountKey(minterAddress, minterPrivateKey);
ret = caver.klay.accounts.wallet.add(ret);
ret = caver.klay.accounts.wallet.getAccount(0);
let mintCount = await contract.methods.getMintedCount(minterAddress).call();
console.log(mintCount);
});
program
.command('nftBurn')
.argument(
'<number>',
'Number of NFTs you want to burn',
)
.requiredOption(
'-n, --network <string>',
'JSON file with gacha machine settings',
)
.action(async (files,options, cmd) => {
const tokenId = parseInt(cmd.args[0]);
console.log(options);
let rpcURL;
let ret;
let contract;
const configBuffer = fs.readFileSync('./config.json');
const configJson = configBuffer.toString();
const configData = JSON.parse(configJson);
const cacheBuffer = fs.readFileSync(CACHE_PATH);
const cacheJson = cacheBuffer.toString();
const dataCache = JSON.parse(cacheJson);
const imageExtension = configData.imageExtension;
let caver;
if(options.network == 'baobab'){
rpcURL = contractData.baobabRPCURL;
caver = await new Caver(rpcURL);
gachaAddress = dataCache.NFTContract;
gachaABI = contractData.NFTABI;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else if(options.network == 'mainnet'){
rpcURL = contractData.mainnetRPCURL;
caver = await new Caver(rpcURL);
gachaAddress = dataCache.NFTContract;
gachaABI = contractData.NFTABI;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else{
throw new Error(
'The Network name is wrong. 네트워크명은 baobab이나 mainnet으로 입력 바랍니다.',
);
}
const minterAddress = configData.TreasuryAccount;
const minterPrivateKey = configData.PrivateKey;
ret = caver.klay.accounts.createWithAccountKey(minterAddress, minterPrivateKey);
ret = caver.klay.accounts.wallet.add(ret);
ret = caver.klay.accounts.wallet.getAccount(0);
ret = await caver.klay.sendTransaction({
type: 'SMART_CONTRACT_EXECUTION',
from: minterAddress,
to: gachaAddress,
data: contract.methods.burnSingle(tokenId).encodeABI(),
gas: "1000000"
}).then(async (res)=>{
console.log("Burn has succeded");
})
.catch((err) => {
console.log(err);
console.log("Burn has failed.");
console.log("소각할 가스비가 모자라거나, 소각할 NFT의 소유자가 아닐 수 있습니다.");
});
});
program
.command('setPurchaseLimit')
.argument(
'<number>',
'Number of NFTs you want to set the purchase limit',
)
.requiredOption(
'-n, --network <string>',
'JSON file with gacha machine settings',
)
.action(async (files,options, cmd) => {
const purchaseLimit = parseInt(cmd.args[0]);
console.log(options);
let rpcURL;
let ret;
let contract;
const configBuffer = fs.readFileSync('./config.json');
const configJson = configBuffer.toString();
const configData = JSON.parse(configJson);
const cacheBuffer = fs.readFileSync(CACHE_PATH);
const cacheJson = cacheBuffer.toString();
const dataCache = JSON.parse(cacheJson);
const imageExtension = configData.imageExtension;
let caver;
if(options.network == 'baobab'){
rpcURL = contractData.baobabRPCURL;
caver = await new Caver(rpcURL);
gachaAddress = dataCache.NFTContract;
gachaABI = contractData.NFTABI;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else if(options.network == 'mainnet'){
rpcURL = contractData.mainnetRPCURL;
caver = await new Caver(rpcURL);
gachaAddress = dataCache.NFTContract;
gachaABI = contractData.NFTABI;
contract = await caver.contract.create(gachaABI, gachaAddress);
}else{
throw new Error(
'The Network name is wrong. 네트워크명은 baobab이나 mainnet으로 입력 바랍니다.',
);
}
const minterAddress = configData.TreasuryAccount;
const minterPrivateKey = configData.PrivateKey;
ret = caver.klay.accounts.createWithAccountKey(minterAddress, minterPrivateKey);
ret = caver.klay.accounts.wallet.add(ret);
ret = caver.klay.accounts.wallet.getAccount(0);
ret = await caver.klay.sendTransaction({
type: 'SMART_CONTRACT_EXECUTION',
from: minterAddress,
to: gachaAddress,
data: contract.methods.updatePurchaseLimit(purchaseLimit).encodeABI(),
gas: "1000000"
}).then(async (res)=>{
console.log("Purchase limit set has been done");
})
.catch((err) => {
console.log(err);
console.log("Purchase limit set has failed");
console.log("가스비를 체크해주시기 바랍니다.");
});
});
async function wait(ms){
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, ms);
});
}
program.parse();