Skip to content

Commit

Permalink
将随机钱包地址修改为获取最新交易地址
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsongsu committed Mar 9, 2024
1 parent 86ba8ca commit 823e2ab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#### 5、运行程序

`node taskRunner.js`
`node taskRunner.js` 已经废弃

自动执行全部的日常签到脚本,每天都需要运行一次

Expand Down
66 changes: 41 additions & 25 deletions src/lavaNet/lavaRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,66 @@ const config = require('../../config/runner.json');
// 代理服务器URL
const proxyUrl = config.proxy;

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
async function getLatestBlockTransactions(rpcUrl, proxyUrl) {
const jsonRpcPayloadForBlockNumber = {
jsonrpc: "2.0",
method: "eth_blockNumber",
params: [],
id: 1,
};

const blockNumberResponse = await fetchWithProxy(rpcUrl, jsonRpcPayloadForBlockNumber, proxyUrl);
if (blockNumberResponse.error) {
throw new Error(blockNumberResponse.error.message);
}

const blockNumber = blockNumberResponse.result;

const jsonRpcPayloadForBlockTransactions = {
jsonrpc: "2.0",
method: "eth_getBlockByNumber",
params: [blockNumber, true],
id: 1,
};

const blockTransactionsResponse = await fetchWithProxy(rpcUrl, jsonRpcPayloadForBlockTransactions, proxyUrl);
if (blockTransactionsResponse.error) {
throw new Error(blockTransactionsResponse.error.message);
}

const transactions = blockTransactionsResponse.result.transactions;
if (transactions.length === 0) {
throw new Error("最新区块中没有交易。");
}

const randomTxIndex = Math.floor(Math.random() * transactions.length);
const fromAddress = transactions[randomTxIndex].from;
return fromAddress;
}

async function main() {
const rpcData = await fs.readFile('rpcData.csv', 'utf8');
const lines = rpcData.split('\n').slice(1); // 去除标题行
const rpcUrls = lines.map(line => {
const columns = line.split(',');
// 确保每行都有至少4列(即index为3的列存在)
return columns.length > 3 ? columns[3] : undefined;
}).filter(url => url && url.trim()); // 过滤掉undefined和空字符串
}).filter(url => url && url.trim()); // 过滤掉空URL

let counter = 0; // 添加一个计数器以跟踪已处理的地址数量

while (true) { // 修改为死循环
const mnemonic = ethers.Wallet.createRandom().mnemonic.phrase;
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
const address = wallet.address;

// 随机选择一个RPC URL,确保了rpcUrls中不会有undefined或空字符串
const rpcUrl = rpcUrls[Math.floor(Math.random() * rpcUrls.length)];
try {
const result = await checkBalanceAndAppend(address, rpcUrl, config.proxy); // 确保proxyUrl来自配置或正确设置
const address = await getLatestBlockTransactions(rpcUrl, config.proxy);
const result = await checkBalanceAndAppend(address, rpcUrl, config.proxy);
counter++;
console.log(`${counter}: ${result}`);
const delay = Math.floor(Math.random() * (9000)) + 1000; // 产生1秒到10秒之间的随机延迟
console.log(`等待 ${delay / 1000} 秒...`);
await sleep(delay);
} catch (error) {
console.error(`查询地址 ${address} 出错: ${error.message}`);
console.error(`查询地址出错: ${error.message}`);
}
}
}


async function fetchWithProxy(url, body, proxyUrl) {
const agent = new HttpsProxyAgent(proxyUrl);
const response = await fetch(url, {
Expand All @@ -53,13 +77,13 @@ async function fetchWithProxy(url, body, proxyUrl) {
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
throw new Error(`请求出错,返回代码: ${response.status}`);
}
return await response.json();
}

async function checkBalanceAndAppend(address, rpcUrl, proxyUrl) {
console.log(`Using RPC: ${rpcUrl}`);
console.log(`使用RPC: ${rpcUrl}`);
const jsonRpcPayload = {
jsonrpc: "2.0",
method: "eth_getBalance",
Expand All @@ -76,12 +100,4 @@ async function checkBalanceAndAppend(address, rpcUrl, proxyUrl) {
return `地址: ${address} - 余额: ${balance} ETH`;
}

function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]]; // Swap
}
return array;
}

main().catch(console.error);
1 change: 1 addition & 0 deletions src/lavaNet/rpcData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Address,NEAR,STRK,ETH,AXELAR

0 comments on commit 823e2ab

Please sign in to comment.