forked from mxnster/sui-testnet-nft-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
152 lines (129 loc) · 5.5 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
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
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',
], [
'Ethos 2048 Game',
'This player has unlocked the 2048 tile on Ethos 2048. They are a Winner!',
'https://arweave.net/QW9doLmmWdQ-7t8GZ85HtY8yzutoir8lGEJP9zOPQqA',
], [
"Sample NFT 1",
"Sample NFT",
"https://cdn.martianwallet.xyz/assets/sample-nft.png"
], [
"Sui Test Ecosystem",
"Get ready for the Suinami 🌊",
"ipfs://QmVnWhM2qYr9JkjGLaEVSZnCprRLDW8qns1oYYVXjnb4DA/sui.jpg"
], [
"Skull Sui",
"Skulls are emerging from the ground!",
"https://gateway.pinata.cloud/ipfs/QmcsJtucGrzkup9cZp2N8vvTc9zxuQtV85z3g2Rs4YRLGX"
]]
function parseFile(file) {
let data = fs.readFileSync(file, "utf8");
let array = data.split('\n').map(str => str.trim());
const proxyRegex = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})@(\w+):(\w+)/;
let proxyLists = [];
array.forEach(proxy => {
if (proxy.match(proxyRegex)) {
proxyLists.push({ "ip": `http://${proxy.split("@")[1]}@${proxy.split("@")[0]}`, "limited": false, "authFailed": false })
}
})
return proxyLists
}
function saveMnemonic(mnemonic) {
fs.appendFileSync("mnemonic.txt", `${mnemonic}\n`, "utf8");
}
async function checkProxy(proxyList) {
let checkedProxy = await Promise.all(proxyList.map(async (proxy) => {
let axiosInstance = axios.create({ httpsAgent: HttpsProxyAgent(proxy.ip) })
await axiosInstance.get("https://api64.ipify.org/?format=json")
.catch(err => {
console.log(`Proxy ${proxy.ip.split("@")[1]} check error: ${err?.response?.statusText}`)
switch (err?.response?.status) {
case 407: proxy.authFailed = true;
case 429: proxy.limited = true;
}
});
return proxy
}))
return checkedProxy.filter((proxy) => !proxy.limited && !proxy.authFailed);
}
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(async err => {
console.log('Faucet error:', err?.response?.statusText || err.code)
if (err?.response?.status == 429) {
proxy.limited = true;
console.log(`Proxy rate limited, need to wait ${err.response.headers['retry-after']} seconds`);
await timeout(5000)
}
})
res?.data && 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');
console.log(`Found ${proxyList.length} proxies`);
let validProxy = await checkProxy(proxyList);
validProxy.length == proxyList.length ? console.log('All proxies are valid') : console.log(`Valid ${validProxy.length}/${proxyList.length} proxies`);
if (validProxy.length > 0) {
while (validProxy.every(proxy => !proxy.limited)) {
for (let i = 0; i < validProxy.length; i++) {
try {
const mnemonic = bip39.generateMnemonic()
const keypair = Ed25519Keypair.deriveKeypair(mnemonic);
const address = keypair.getPublicKey().toSuiAddress()
let response = await requestSuiFromFaucet(validProxy[i], address)
if (response) {
console.log(`Sui Address: 0x${address}`)
console.log(`Mnemonic: ${mnemonic}`);
saveMnemonic(mnemonic);
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`);
}
} catch (err) {
console.log(err.message);
await timeout(10000)
}
console.log("-".repeat(100));
}
}
} else console.log('No working proxies found, please make sure the proxy is in the correct format');
})()