-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
199 lines (166 loc) · 6.85 KB
/
index.js
File metadata and controls
199 lines (166 loc) · 6.85 KB
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
import { ethers } from "ethers";
import dotenv from "dotenv";
import fs from "fs";
import chalk from "chalk";
import figlet from "figlet";
import { exit } from "process";
dotenv.config();
// Ambil semua RPC dari .env
function getRpcList() {
const rpcList = [];
for (let i = 1; ; i++) {
const name = process.env[`RPC_${i}_NAME`];
const url = process.env[`RPC_${i}_URL`];
const token = process.env[`RPC_${i}_TOKEN`];
if (!name || !url) break;
rpcList.push({ name, url, token });
}
return rpcList;
}
// ABI ERC-20
const erc20Abi = [
"function balanceOf(address owner) view returns (uint256)",
"function transfer(address to, uint256 value) returns (bool)",
"function decimals() view returns (uint8)",
"function symbol() view returns (string)",
];
// Fungsi untuk menampilkan banner (sync)
function showBanner() {
console.clear();
const banner = figlet.textSync("AUTO TRANSFER", {
font: "Standard",
horizontalLayout: "default",
verticalLayout: "default",
});
// Menambahkan padding untuk memposisikan [by WIN] dan garis pemisah di tengah
const lines = banner.split("\n");
const byWinText = "[by WIN] from Airdrop Seeker";
const divider = "=".repeat(lines[0].length);
const padding = ' '.repeat(Math.floor((lines[0].length - byWinText.length) / 2)); // Menentukan padding agar [by WIN] terpusat
const dividerPadding = ' '.repeat(Math.floor((lines[0].length - divider.length) / 2)); // Menentukan padding agar divider terpusat
// Menampilkan banner dengan [by WIN] dan garis pemisah yang terpusat
console.log(chalk.greenBright(banner));
console.log(chalk.greenBright(`${dividerPadding}${divider}`)); // Garis pemisah yang terpusat
console.log(chalk.greenBright(`${padding}${byWinText}`)); // Menambahkan padding ke [by WIN]
console.log(chalk.greenBright(`${dividerPadding}${divider}`)); // Garis pemisah yang terpusat
}
// Input dari user
async function askQuestion(query) {
process.stdout.write(chalk.yellow(query));
return new Promise((resolve) => {
process.stdin.once("data", (data) => resolve(data.toString().trim()));
});
}
// Ambil info token
async function getTokenInfo(provider, tokenAddress) {
const tokenContract = new ethers.Contract(tokenAddress, erc20Abi, provider);
const decimals = await tokenContract.decimals();
const symbol = await tokenContract.symbol();
return { decimals, symbol };
}
// Fungsi utama transfer
async function autoTransfer(selectedRpc) {
const receiverFile = "addresspenerima.txt";
const senderFile = "walletpengirim.txt";
if (!fs.existsSync(receiverFile) || !fs.existsSync(senderFile)) {
console.log(chalk.red(`❌ File '${receiverFile}' atau '${senderFile}' tidak ditemukan.`));
exit(1);
}
const recipients = fs.readFileSync(receiverFile, "utf8").split("\n").map(p => p.trim()).filter(p => p.length > 0);
const privateKeys = fs.readFileSync(senderFile, "utf8").split("\n").map(p => p.trim()).filter(p => p.length > 0);
const provider = new ethers.JsonRpcProvider(selectedRpc.url);
const tokenAddress = selectedRpc.token;
const mode = await askQuestion("Pilih mode transfer! (1 = Token Native, 2 = Token ERC-20): ");
if (!["1", "2"].includes(mode)) {
console.log(chalk.red("❌ Pilihan tidak valid!"));
exit(1);
}
const transferAll = await askQuestion("Transfer semua saldo? (y/n): ");
const amountInput = transferAll.toLowerCase() === "y"
? "ALL"
: await askQuestion("Masukkan jumlah Token yang akan dikirim (contoh: 0.005): ");
console.log(chalk.yellow(`\n🚀 Chain: ${selectedRpc.name} | Mode: ${mode === "1" ? "Native" : "ERC-20"} | Jumlah: ${amountInput}\n`));
let tokenInfo;
if (mode === "2") {
tokenInfo = await getTokenInfo(provider, tokenAddress);
}
for (let i = 0; i < privateKeys.length; i++) {
console.log(chalk.cyanBright(`👩💻 [${i + 1}] Memproses wallet ke-${i + 1}...`));
let senderWallet;
try {
senderWallet = new ethers.Wallet(privateKeys[i], provider);
} catch (error) {
console.log(chalk.red(`❌ Gagal inisialisasi wallet: ${error.message}`));
continue;
}
if (mode === "2") {
const tokenContract = new ethers.Contract(tokenAddress, erc20Abi, senderWallet);
try {
const balance = await tokenContract.balanceOf(senderWallet.address);
console.log(chalk.greenBright(`✅ Saldo token: ${ethers.formatUnits(balance, tokenInfo.decimals)} ${tokenInfo.symbol}`));
let rawAmount = amountInput === "ALL" ? balance : ethers.parseUnits(amountInput, tokenInfo.decimals);
if (balance < rawAmount) {
console.log(chalk.red("❌ Saldo tidak cukup."));
continue;
}
for (const [j, recipient] of recipients.entries()) {
try {
const tx = await tokenContract.transfer(recipient, rawAmount);
console.log(chalk.green(`✅ (${j + 1}) TX Hash: ${tx.hash}`));
await tx.wait();
} catch (err) {
console.log(chalk.red(`❌ Gagal transfer ke ${recipient}: ${err.message}`));
}
await new Promise(r => setTimeout(r, 3000));
}
} catch (err) {
console.log(chalk.red(`❌ Gagal memproses token: ${err.message}`));
}
} else {
try {
const balance = await provider.getBalance(senderWallet.address);
console.log(chalk.greenBright(`✅ Saldo native: ${ethers.formatEther(balance)}`));
let rawAmount = amountInput === "ALL" ? balance : ethers.parseEther(amountInput);
if (balance < rawAmount) {
console.log(chalk.red("❌ Saldo tidak cukup bang."));
continue;
}
for (const [j, recipient] of recipients.entries()) {
try {
const tx = await senderWallet.sendTransaction({ to: recipient, value: rawAmount });
console.log(chalk.green(`✅ (${j + 1}) TX Hash: ${tx.hash}`));
await tx.wait();
} catch (err) {
console.log(chalk.red(`❌ Gagal kirim ke ${recipient}: ${err.message}`));
}
await new Promise(r => setTimeout(r, 3000));
}
} catch (err) {
console.log(chalk.red(`❌ Gagal kirim native: ${err.message}`));
}
}
}
console.log(chalk.greenBright("\n🎉 Semua akun telah diproses!\n"));
}
// Fungsi start
async function start() {
showBanner();
const rpcList = getRpcList();
if (rpcList.length === 0) {
console.log(chalk.red("❌ Tidak ada RPC ditemukan di .env"));
exit(1);
}
console.log("Daftar Chain Mainnet/Testnet:");
rpcList.forEach((rpc, index) => {
console.log(`${index + 1}. ${rpc.name}`);
});
const selectedIndex = await askQuestion("Pilih CHAIN (nomor): ");
const selectedRpc = rpcList[Number(selectedIndex) - 1];
if (!selectedRpc) {
console.log(chalk.red("❌ Pilihan tidak valid!"));
exit(1);
}
console.log(chalk.green(`\n✅ Kamu memilih: ${selectedRpc.name}\n`));
await autoTransfer(selectedRpc);
}
start();