-
Notifications
You must be signed in to change notification settings - Fork 1
/
mint.js
executable file
·81 lines (72 loc) · 2.91 KB
/
mint.js
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
#!/usr/bin/env node
const { transact } = require('./api')
const { ACCOUNT, COLLECTION, ACCOUNT_PERMISSION } = require('./constants')
const pressAnyKey = require('./node_modules/press-any-key')
var argv = require('yargs/yargs')(process.argv)
.command('Mint NFTs by specifying collectionName, schemaName, templateId, desired quantity & (optional) the new owner (receiver)')
.example('$0 -c flytothemoon -t 26 -s 1stedition -q 10', 'Mint 10 NFTs')
.example('$0 -c flytothemoon -t 26 -s 1stedition -q 10 -r cryptotester', 'Mint 10 NFTs specifying cryptotester as new owner')
.describe('collection_name', 'Collection name')
.alias('c', 'collection_name')
.default('collection_name', COLLECTION)
.describe('schema_name', 'Schema name')
.alias('s', 'schema_name')
.describe('template_id', 'template_id')
.alias('t', 'template_id')
.describe('quantity', 'quantity')
.alias('q', 'quantity')
.describe('receiver', 'Receiver')
.alias(['r', 'to'], 'receiver')
.boolean(['debug'])
.demandOption(['collection_name', 'schema_name', 'template_id', 'quantity'])
.argv
const mintNfts = async (collectionName, schemaName, templateId, quantity, receiver = undefined) => {
if (collectionName === '' || collectionName === undefined) {
console.log('Error, you must define a collection name by using the option -c collectionName')
return
}
if (receiver === undefined) {
receiver = ACCOUNT
}
let batch = []
for (let i = 1; i <= quantity; i++) {
const trx = {
"account": "atomicassets",
"name": "mintasset",
"authorization": [{
"actor": ACCOUNT,
"permission": ACCOUNT_PERMISSION
}],
"data": {
"authorized_minter": ACCOUNT,
"collection_name": collectionName,
"schema_name": schemaName,
"template_id": templateId,
"new_asset_owner": receiver,
"immutable_data": [],
"mutable_data": [],
"tokens_to_back": []
}
}
batch.push(trx)
}
const receiverText = (receiver !== ACCOUNT) ? ` that will be owned by ${receiver}` : ''
console.log(`You will mint ${batch.length} NFTs`
+ ` (collection ${collectionName}, template ${templateId}, schema ${schemaName})${receiverText}. Proceed?`)
pressAnyKey('Press ENTER to continue, or Ctrl + C to stop.', {
ctrlC: 'reject'
})
.then(async () => {
if (argv.debug) console.log(batch)
try {
await transact(batch)
console.log(`Minted ${batch.length} NFT with template_id ${templateId}`)
} catch (e) {
console.log(e)
}
})
.catch(() => {
console.log('You pressed Ctrl + C')
})
}
mintNfts(argv.collection_name, argv.schema_name, argv.template_id, argv.quantity, argv.receiver)