first commit

This commit is contained in:
jack
2025-11-12 16:47:21 +08:00
commit 266ba871a4
43 changed files with 3747 additions and 0 deletions
@@ -0,0 +1,66 @@
import { ethers } from "ethers";
// 设置 RPC URL
const rpcUrl = "https://testnet-rpc.monad.xyz";
// 初始化 ethers.js 提供器
const provider = new ethers.JsonRpcProvider(rpcUrl);
// 检查是否连接成功
async function checkConnection() {
try {
const network = await provider.getNetwork();
console.log(`已成功连接到链节点,网络ID为: ${network.chainId}。正在查询钱包余额...`);
return true;
} catch (error) {
console.log("无法连接到链节点,请检查 URL 是否正确");
return false;
}
}
// 替换为实际的钱包地址列表
const walletAddresses = [
"0x10A43E7Fe77E2D84adBeC26cF0bFc6f403841266",
"0x70D5EE1DfddD3726f0D71F4CD5a8ef43aC651a75"
];
async function queryBalances() {
const isConnected = await checkConnection();
if (!isConnected) {
return;
}
for (const walletAddress of walletAddresses) {
let retryCount = 0;
const maxRetries = 3;
const delay = 2000; // 延迟时间,单位为毫秒
let resultMessage = "";
let resultBalance = -1;
while (retryCount < maxRetries) {
try {
// 查询余额
const balance = await provider.getBalance(walletAddress);
// 将余额从 Wei 转换为 Ether
const balanceEth = ethers.formatUnits(balance, 18);
resultMessage = `Wallet address: ${walletAddress}, balance: ${balanceEth} Token`;
resultBalance = balanceEth;
console.log(resultMessage);
break;
} catch (e) {
console.log(`查询钱包 ${walletAddress} 余额时发生错误: ${e.message}`);
retryCount += 1;
console.log(`正在重试...(第 ${retryCount} 次)`);
await new Promise((resolve) => setTimeout(resolve, delay));
}
}
if (retryCount === maxRetries) {
resultMessage = `钱包 ${walletAddress} 查询余额失败,已达到最大重试次数。`;
console.log(resultMessage);
}
}
}
queryBalances();
+58
View File
@@ -0,0 +1,58 @@
import { ethers } from 'ethers';
const providerUrl = 'https://testnet-rpc.monad.xyz';
const provider = new ethers.JsonRpcProvider(providerUrl);
const privateKeyList = [
'2a185eae14ca82ac934a5f952e12e0d4a64043c911c33a19afd48ef1a1d70c46',
// Add more private keys here
// 'your_second_private_key',
// 'your_third_private_key',
];
const stakingContractAddress = '0xcBE623D259261FFa0CFAff44484bFF46c1b7D6c2';
// Function to generate random delay between 5-10 seconds
const getRandomDelay = () => {
return Math.floor(Math.random() * (10000 - 5000 + 1)) + 5000;
};
// Function to handle staking for a single wallet
async function stakeMon(wallet) {
try {
const balance = await provider.getBalance(wallet.address);
console.log(`Wallet ${wallet.address} balance:`, ethers.formatEther(balance));
const amountToStake = ethers.parseEther('0');
if (balance < amountToStake) {
throw new Error(`Insufficient balance for staking in wallet ${wallet.address}`);
}
const tx = await wallet.sendTransaction({
to: stakingContractAddress,
value: amountToStake,
data: '0x7ab71841',
gasLimit: 1000000,
gasPrice: ethers.parseUnits('52', 'gwei')
});
console.log(`Stake transaction hash for ${wallet.address}:`, tx.hash);
const receipt = await tx.wait();
console.log(`Stake transaction receipt for ${wallet.address}:`, receipt);
} catch (error) {
console.error(`Error staking $MON for ${wallet.address}:`, error);
}
}
// Function to process all wallets with delay
async function processAllWallets() {
for (const privateKey of privateKeyList) {
const wallet = new ethers.Wallet(privateKey, provider);
await stakeMon(wallet);
// Add random delay between 5-10 seconds, except for the last wallet
if (privateKey !== privateKeyList[privateKeyList.length - 1]) {
const delay = getRandomDelay();
console.log(`Waiting ${delay/1000} seconds before next wallet...`);
await new Promise(resolve => setTimeout(resolve, delay));
}
}
}
processAllWallets();
+33
View File
@@ -0,0 +1,33 @@
import { ethers } from 'ethers';
// 使用 ethers.js 的 Provider
const rpcUrl = 'https://testnet-rpc.monad.xyz';
const provider = new ethers.JsonRpcProvider(rpcUrl);
const addresses = [
'0x10A43E7Fe77E2D84adBeC26cF0bFc6f403841266',
'0x70D5EE1DfddD3726f0D71F4CD5a8ef43aC651a75'
];
// 测试钱包
// const addresses = ['0x10A43E7Fe77E2D84adBeC26cF0bFc6f403841266']
async function getNonces() {
try {
let countNum = 1;
for (const address of addresses) {
// 获取最新的 nonce
const nonceLatest = await provider.getTransactionCount(address, 'latest');
const noncePending = await provider.getTransactionCount(address, 'pending');
const countNumStr = String(countNum).padStart(2, '0');
console.log(`${countNumStr} address: ${address}`);
console.log(`pending nonce: ${noncePending} ; latest nonce: ${nonceLatest}`);
console.log('-----------------------------');
countNum++;
}
} catch (error) {
console.error('获取 nonce 时发生错误:', error.message);
}
}
getNonces();
+38
View File
@@ -0,0 +1,38 @@
import { ethers } from 'ethers';
// 替换为您的节点URL
const providerUrl = 'https://testnet-rpc.monad.xyz';
const provider = new ethers.JsonRpcProvider(providerUrl);
// 替换为您的钱包私钥(发送方钱包)
const privateKey = '0x3991542110242368f4770716be904b0ca6d44a8dbe4501771833b1a3642198d1'; // 私钥
const wallet = new ethers.Wallet(privateKey, provider);
// 接收方钱包地址
const recipientAddress = '0x70D5EE1DfddD3726f0D71F4CD5a8ef43aC651a75';
// 发送代币的函数
async function sendToken() {
try {
const amountToSend = ethers.parseEther('0.0000001'); // 发送数量
// 构造交易对象
const tx = {
to: recipientAddress,
value: amountToSend
};
// 发送交易
const txResponse = await wallet.sendTransaction(tx);
console.log('Transaction hash:', txResponse.hash);
// 等待交易确认
const receipt = await txResponse.wait();
console.log('Transaction receipt:', receipt);
} catch (error) {
console.error('Error sending Token:', error);
}
}
// 调用发送Token的函数
sendToken();