You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.6 KiB

import {ethers} from "ethers";
import fs from 'fs/promises';
import path from 'path';
import {fileURLToPath} from 'url';
// 使用 ethers.js 的 Provider
const rpcUrl = 'https://testnet-rpc.monad.xyz';
const provider = new ethers.JsonRpcProvider(rpcUrl);
// 读取私钥文件
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const filePath = path.join(__dirname, './AccountList.txt');
async function getNonces(privateKeys) {
let countNum = 1;
for (const privateKey of privateKeys) {
try {
const wallet = new ethers.Wallet(privateKey, provider);
//获取最新的 nonce
const nonceLatest = await provider.getTransactionCount(wallet, 'latest');
const noncePending = await provider.getTransactionCount(wallet, 'pending');
const countNumStr = String(countNum).padStart(2, '0');
console.log(`${countNumStr} address: ${wallet.address}`);
console.log(`pending nonce: ${noncePending} ; latest nonce: ${nonceLatest}`);
console.log('-----------------------------');
countNum++;
} catch (error) {
console.error('获取 nonce 时发生错误:', error.message);
}
}
}
async function main() {
try {
const data = await fs.readFile(filePath, 'utf8');
const privateKeys = data.split('\n').filter(line => line.trim() !== '');
await getNonces(privateKeys);
} catch (err) {
console.error('读取文件时发生错误:', err);
process.exit(1);
}
}
main();