-
Notifications
You must be signed in to change notification settings - Fork 0
/
ripplex7-batch-minting.js
182 lines (150 loc) · 6.03 KB
/
ripplex7-batch-minting.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
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
// *******************************************************
// ************ Get Account from Seed ******************
// *******************************************************
async function getAccountFromSeed() {
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
standbyResultField.value = results
await client.connect()
results += '\nConnected, finding wallets.\n'
standbyResultField.value = results
// -------------------------------------------- Find the test account wallet.
var theSeed = seeds.value
const standby_wallet = xrpl.Wallet.fromSeed(theSeed)
// ------------------------------------------------- Get the current balance.
const standby_balance = (await client.getXrpBalance(standby_wallet.address))
// --------------------------------- Populate the fields for Standby account.
standbyAccountField.value = standby_wallet.address
standbyPubKeyField.value = standby_wallet.publicKey
standbyPrivKeyField.value = standby_wallet.privateKey
standbySeedField.value = standby_wallet.seed
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
client.disconnect()
} // End of getAccountsFromSeeds()
// *******************************************************
// **************** Get Batch Tokens *********************
// *******************************************************
async function getBatchNFTs() {
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
standbyResultField.value = results
await client.connect()
results += '\nConnected. Getting NFTs...'
standbyResultField.value = results
results += "\n\nNFTs:\n"
let nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress,
limit: 400
})
results += JSON.stringify(nfts,null,2)
while (nfts.result.marker)
{
nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress,
limit: 400,
marker: nfts.result.marker
})
results += '\n' + JSON.stringify(nfts,null,2)
}
standbyResultField.value = results
client.disconnect()
} //End of getBatchTokens()
// *******************************************************
// ****************** Batch Mint ***********************
// *******************************************************
async function batchMint() {
//--------------------- Connect to the XRP Ledger and get the account wallet.
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
standbyResultField.value = results
await client.connect()
results += '\nConnected, finding wallet.'
standbyResultField.value = results
standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
standbyResultField.value = results
//----------------- Get account information, particularly the Sequence number.
const account_info = await client.request({
"command": "account_info",
"account": standby_wallet.address
})
my_sequence = account_info.result.account_data.Sequence
results += "\n\nSequence Number: " + my_sequence + "\n\n"
standbyResultField.value = results
/* ###################################
Create ticket numbers for the batch
Without tickets, if one transaction fails, all others in the batch fail.
With tickets, there can be failures, but the rest will continue, and you
can investigate any problems afterward.
*/
//---------------------- Parse the requested number from NFTokenCountField.
const nftokenCount = parseInt(standbyNFTokenCountField.value)
//-------------------------------------------- Create the transaction hash.
const ticketTransaction = await client.autofill({
"TransactionType": "TicketCreate",
"Account": standby_wallet.address,
"TicketCount": nftokenCount,
"Sequence": my_sequence
})
//---------------------------------------------------- Sign the transaction.
const signedTransaction = standby_wallet.sign(ticketTransaction)
//-------------------------- Submit the transaction and wait for the result.
const tx = await client.submitAndWait(signedTransaction.tx_blob)
let response = await client.request({
"command": "account_objects",
"account": standby_wallet.address,
"type": "ticket"
})
//------------------------------------ Populate the tickets array variable.
let tickets = []
for (let i=0; i < nftokenCount; i++) {
tickets[i] = response.result.account_objects[i].TicketSequence
}
//-------------------------------------------------------- Report progress.
results += "Tickets generated, minting NFTs.\n\n"
standbyResultField.value = results
// ###################################
// Mint NFTs
for (let i=0; i < nftokenCount; i++) {
const transactionBlob = {
"TransactionType": "NFTokenMint",
"Account": standby_wallet.classicAddress,
"URI": xrpl.convertStringToHex(standbyTokenUrlField.value),
"Flags": parseInt(standbyFlagsField.value),
"TransferFee": parseInt(standbyTransferFeeField.value),
"Sequence": 0,
"TicketSequence": tickets[i],
"LastLedgerSequence": null,
"NFTokenTaxon": 0
}
//------------------------------------------------------ Submit signed blob.
const tx = client.submit(transactionBlob, { wallet: standby_wallet} )
}
results += "\n\nNFTs:\n"
let nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress,
limit: 400
})
results += JSON.stringify(nfts,null,2)
while (nfts.result.marker)
{
nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress,
limit: 400,
marker: nfts.result.marker
})
results += '\n' + JSON.stringify(nfts,null,2)
}
results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult
results += '\n\nNFTs: ' + JSON.stringify(nfts, null, 2)
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
standbyResultField.value = results
client.disconnect()
} // End of batchMint()