forked from mxnster/sui-testnet-nft-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
107 lines (86 loc) · 3.37 KB
/
index.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
import { Ed25519Keypair, JsonRpcProvider, RawSigner } from '@mysten/sui.js';
import bip39 from 'bip39'
import axios from 'axios'
import HttpsProxyAgent from 'https-proxy-agent';
import fs from 'fs';
import consoleStamp from 'console-stamp';
consoleStamp(console, { format: ':date(HH:MM:ss)' });
const timeout = ms => new Promise(res => setTimeout(res, ms))
const provider = new JsonRpcProvider('https://fullnode.testnet.sui.io')
const nftArray = [[
'Example NFT',
'An NFT created by Sui Wallet',
'ipfs://QmZPWWy5Si54R3d26toaqRiqvCH7HkGdXkxwUgCm2oKKM2?filename=img-sq-01.png',
], [
'Example NFT',
'An NFT created by the wallet Command Line Tool',
'ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty',
], [
'Wizard Land',
'Expanding The Magic Land',
'https://gateway.pinata.cloud/ipfs/QmYfw8RbtdjPAF3LrC6S3wGVwWgn6QKq4LGS4HFS55adU2?w=800&h=450&c=crop',
]]
function parseFile(file) {
let data = fs.readFileSync(file, "utf8");
let array = data.split('\r\n');
return array.map(proxy => ({ "ip": `http://${proxy.split("@")[1]}@${proxy.split("@")[0]}`, "limited": false }))
}
function saveMnemonic(mnemonic) {
fs.appendFileSync("mnemonic.txt", `${mnemonic}\n`, "utf8");
}
async function requestSuiFromFaucet(proxy, recipient) {
console.log(`Requesting sui from faucet with proxy ${proxy.ip.split("@")[1]}`);
const axiosInstance = axios.create({ httpsAgent: HttpsProxyAgent(proxy.ip) })
let res = await axiosInstance("https://faucet.testnet.sui.io/gas", {
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify({
FixedAmountRequest: { recipient },
}),
method: "POST"
}).catch(err => {
console.log('Faucet error:', err.response.statusText)
if (err.response.status == 429) {
proxy.limited = true;
}
})
console.log(`Faucet request status: ${res?.statusText}`);
return res?.data
}
async function mintNft(signer, args) {
console.log(`Minting: ${args[1]}`);
return await signer.executeMoveCall({
packageObjectId: '0x2',
module: 'devnet_nft',
function: 'mint',
typeArguments: [],
arguments: args,
gasBudget: 10000,
})
}
(async () => {
let proxyList = parseFile('proxy.txt');
while (proxyList.every(proxy => !proxy.limited)) {
for (let i = 0; i < proxyList.length; i++) {
try {
const mnemonic = bip39.generateMnemonic()
console.log(`Mnemonic: ${mnemonic}`);
saveMnemonic(mnemonic);
const keypair = Ed25519Keypair.deriveKeypair(mnemonic);
const address = keypair.getPublicKey().toSuiAddress()
console.log(`Sui Address: 0x${address}`)
let response = await requestSuiFromFaucet(proxyList[i], address)
if (response) {
const signer = new RawSigner(keypair, provider);
for (let i = 0; i < nftArray.length; i++) {
await mintNft(signer, nftArray[i])
}
console.log(`Result: https://explorer.sui.io/addresses/${address}?network=testnet`);
}
console.log("-".repeat(100));
} catch (err) {
console.log(err.message);
await timeout(10000)
}
}
}
})()