forked from AmazingAng/WTF-ARB-Claimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclaimAirdropSend.js
131 lines (112 loc) · 4.06 KB
/
claimAirdropSend.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
// 发送ETH,claim,发送代币脚本
import { ethers } from "ethers";
import {} from 'dotenv/config'
// 配置提供者
const provider = new ethers.providers.JsonRpcProvider("Your_RPC_URL");
// 从 .env 文件中读取主钱包和批量钱包的私钥
const mainWalletPrivateKey = process.env.MAIN_WALLET_PRIVATE_KEY;
const batchWalletsPrivateKeys = process.env.PRIVATE_KEYS.split(",");
// 配置空投合约和 ERC20 代币合约的地址和 ABI
const airdropContractAddress = "0x67a24ce4321ab3af51c2d0a4801c3e111d88c9d9";
const erc20TokenContractAddress = "0x912CE59144191C1204E64559FE8253a0e49E6548";
const getETHBlocknumberAddress = "0xE8d4cA5e9713c595Ec1975FC955923DF1439CD8a";
const getETHBlocknumberABI= [
"function getETHBlocknumber() external view returns(uint)"
]
const airdropContractABI = [
"function claim() public",
];
const erc20TokenContractABI = [
"function balanceOf(address) view returns (uint)",
{
inputs: [
{
internalType: "address",
name: "recipient",
type: "address",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
],
name: "transfer",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "nonpayable",
type: "function",
},
];
// 目标区块高度
const targetBlockNumber = 16890400;
// 用于转账的金额(根据需要自行调整)
const transferAmount = ethers.utils.parseEther("0.005");
// 主钱包实例
const mainWallet = new ethers.Wallet(mainWalletPrivateKey, provider);
async function waitForBlockAndClaimAirdropAndSendTokens() {
const airdropContract = new ethers.Contract(
getETHBlocknumberAddress,
getETHBlocknumberABI,
provider
);
while (true) {
const currentBlockNumber = await airdropContract.getETHBlocknumber();
console.log("Current block number:", currentBlockNumber.toString());
if (currentBlockNumber >= targetBlockNumber) {
const tasks = batchWalletsPrivateKeys.map(async (privateKey) => {
const batchWallet = new ethers.Wallet(privateKey, provider);
const airdropContract = new ethers.Contract(
airdropContractAddress,
airdropContractABI,
batchWallet
);
const erc20TokenContract = new ethers.Contract(
erc20TokenContractAddress,
erc20TokenContractABI,
batchWallet
);
// 1. 从主钱包发送 0.001 ETH 到目标钱包
const tx = {
to: batchWallet.address,
value: transferAmount,
};
try {
const txResponse = await mainWallet.sendTransaction(tx);
console.log("Transaction hash:", txResponse.hash);
} catch (error) {
console.error(`Error sending transaction to ${batchWallet.address}:`, error.message);
}
// 2. 目标钱包调用空投合约的 claim() 函数领取空投
try {
const claimTxResponse = await airdropContract.claim();
console.log("Claim transaction hash:", claimTxResponse.hash);
} catch (error) {
console.error(`Error claiming airdrop for wallet ${batchWallet.address}:`, error.message);
}
// 3. 将空投的 ERC20 代币发送给主钱包
try {
const balance = await erc20TokenContract.balanceOf(batchWallet.address);
const transferTxResponse = await erc20TokenContract.transfer(mainWallet.address, balance);
console.log("Transfer transaction hash:", transferTxResponse.hash);
} catch (error) {
console.error(`Error transferring tokens to main wallet from ${batchWallet.address}:`, error.message);
}
});
// 等待所有任务完成
await Promise.all(tasks);
console.log("All tasks have been processed.");
// 任务完成,退出循环
break;
} else {
// 等待 0.1 秒后继续检查区块高度
await new Promise((resolve) => setTimeout(resolve, 100));
}
}
}
waitForBlockAndClaimAirdropAndSendTokens();