| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import {ethers} from "ethers";
- import fs from 'fs/promises';
- import path from 'path';
- import { fileURLToPath } from 'url';
- // Monad 测试网 RPC URL
- const providerUrl = "https://testnet-rpc.monad.xyz";
- const provider = new ethers.JsonRpcProvider(providerUrl);
- // 合约地址、合约方法哈希值及描述
- const contractData = [
- {
- address: "0x2c9c959516e9aaedb2c748224a41249202ca8be7",
- dataHash: "0xd5575982",
- description: "Magmastaking"
- },
- {
- address: "0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701",
- dataHash: "0xd5575982",
- description: "ApeBond"
- },
- {
- address: "0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701",
- dataHash: "0xd0e30db0",
- description: "OctoSwap - WMON"
- }
- ];
- // 读取私钥文件
- const __filename = fileURLToPath(import.meta.url);
- const __dirname = path.dirname(__filename);
- const filePath = path.join(__dirname, './AccountList.txt');
- function sleep(min_delay, max_delay) {
- // 随机睡眠
- const delay = Math.floor(Math.random() * (max_delay * 1000 - min_delay * 1000 + 1)) + min_delay * 1000;
- return new Promise((resolve) => setTimeout(resolve, delay));
- }
- function getRandomAmount() {
- // 生成随机交易金额 0.00000000****(最后4位随机数)
- const randomTail = Math.floor(1000 + Math.random() * 2000); // 生成1000-9999的随机4位数
- return ethers.parseEther(`0.00000000${randomTail}`);
- }
- function getRandomContractData() {
- // 随机获取合约地址、合约方法哈希值及描述
- if (contractData.length === 0) {
- console.error("The contract data array is empty, the contract cannot be selected, and the program exits.");
- process.exit(1);
- }
- const randomIndex = Math.floor(Math.random() * contractData.length);
- return contractData[randomIndex];
- }
- function checkWalletBalance(balance) {
- if (balance <= ethers.parseEther("5")) {
- console.error("The wallet balance is invalid.");
- process.exit(1);
- }
- }
- async function executeContract(wallet) {
- try {
- // 随机选择一个合约地址、合约方法哈希值及描述
- const {address, dataHash, description} = getRandomContractData();
- console.log(`Selected contract: ${description}`);
- console.log("Selected contract address:", address);
- console.log("Selected contract dataHash:", dataHash);
- // 检查原生代币余额
- const balance = await provider.getBalance(wallet.address);
- const beforeBalance = ethers.formatEther(balance);
- console.log("Native balance:", beforeBalance);
- // 检查钱包余额,不能小于 0.2
- checkWalletBalance(balance);
- // 质押金额
- const amountToStake = getRandomAmount();
- console.log("Amount to contract:", ethers.formatEther(amountToStake));
- if (balance < amountToStake) {
- throw new Error("Insufficient balance for contract execution.");
- }
- // 低级调用,发送交易
- const tx = await wallet.sendTransaction({
- to: address,
- value: amountToStake,
- data: dataHash,
- gasLimit: 100000,
- gasPrice: ethers.parseUnits("50", "gwei")
- });
- console.log("Contract Execution hash:", tx.hash);
- // 等待交易确认
- const receipt = await tx.wait();
- console.log("Contract Execution status:", "ok");
- // 检查交易后的余额
- const balanceStaking = await provider.getBalance(wallet.address);
- const afterBalance = ethers.formatEther(balanceStaking);
- console.log("Native balance after transaction:", afterBalance);
- console.log("The cost of this transaction:", parseFloat(beforeBalance) - parseFloat(afterBalance));
- } catch (error) {
- console.error("Error executing contract:", error);
- }
- }
- async function runMultipleStaking(privateKeys) {
- const last_times = 1000;
- const min_delay = 10;
- const max_delay = 20;
- for (const privateKey of privateKeys) {
- const wallet = new ethers.Wallet(privateKey, provider);
- console.log(`Processing wallet with address: ${wallet.address}`);
- for (let i = 0; i < last_times; i++) {
- if (last_times > 1) {
- console.log(`Starting Contract attempt ${i + 1}`);
- }
- await executeContract(wallet);
- console.log(`Completed Contract attempt ${i + 1}`);
- if (i < last_times - 1) {
- // 最后一次循环不等待
- const delay = Math.floor(Math.random() * (max_delay * 1000 - min_delay * 1000 + 1)) + min_delay * 1000;
- console.log(`Waiting for ${delay / 1000} seconds...`);
- console.log('------------------------------------------------------------')
- await sleep(min_delay, max_delay);
- }
- }
- }
- }
- async function main() {
- try {
- const data = await fs.readFile(filePath, 'utf8');
- const privateKeys = data.split('\n').filter(line => line.trim() !== '');
- await runMultipleStaking(privateKeys);
- } catch (err) {
- console.error('读取文件时发生错误:', err);
- process.exit(1);
- }
- }
- main();
|