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.
 
 
 
web3Interactive/reference/test/test_nonce_monad.mjs

33 lines
1.1 KiB

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();