一.交易池
let rpcProvider = new ethers.providers.JsonRpcProvider("")
let pool = await rpcProvider.send("txpool_content", [])
let queue = pool.queued
console.log(queue)
let queueAddress = Object.keys(queue)
{ '0x08b080D53DDF0b553A386d41168556bcD1A521bc':
{ '5':
{ blockHash:
'0x0000000000000000000000000000000000000000000000000000000000000000',
blockNumber: null,
from: '0x08b080d53ddf0b553a386d41168556bcd1a521bc',
gas: '0x73f79b',
gasPrice: '0xb2d05e00',
hash:
'0xd4b06772b11d0f661bb61dd56cea404d29ff7873a57e7aec86978e022eb9d94d',
input:
'0x130d79060000000000000000000000000000000000000000000000000000000001000000',
nonce: '0x5',
to: '0xa92c3969955e55b2667286042a9ae91b0a5febbe',
transactionIndex: '0x0',
value: '0x0',
v: '0x2a',
r:
'0x2ebf73f1dcc04f744476bf9ab67a74a9c7f3af94c67ed6b43ef62226bc16f5c6',
s:
'0x6393c4b60e415552fafc7905ea02fa3248ebdc90f7d1121f313eca05ca136e' } },
'0xd95389b41FaA140a80d3172a1a206aE96416b1c4':
{ '4':......
}}}}
二、 pending交易
let pendingList = []
let pendingResult = []
let allPendingList = await rpcProvider.send("eth_pendingTransactions", [])
for (let i = 0; i < allPendingList.length; i++) {
if (allPendingList[i].from === address.toLowerCase() || allPendingList[i].to === address.toLowerCase()) {
pendingList.push(allPendingList[i])
}
}
console.log(pendingList)
console.log("alllength:" + allPendingList.length)
// console.log(allPendingList)
for (let i = 0; i < pendingList.length; i++) {
let pendingAmount = ethers.utils.formatEther(pendingList[i].value).substr(0, 10)
if (address.toLowerCase() === pendingList[i].from) {
flag = 0
pendingAmount = -pendingAmount
}
let a = new Date();
let year = a.getFullYear();
let month = a.getMonth() + 1;
let date = a.getDate();
let hour = a.getHours();
let min = a.getMinutes();
let sec = a.getSeconds();
let time = year + '-' + month + '-' + date + ' ' + hour + ':' + min + ':' + sec;
let pending = {
// nonce:pendingList[i].nonce,
txHash: pendingList[i].hash,
transferAmount: pendingAmount+"",
from: pendingList[i].from,
to: pendingList[i].to,
state: 0,
flag: flag,
// transactionTime: time
}
pendingResult.push(pending)
}
console.log(pendingResult)
let pendingSize = pendingList.length
console.log("pendingSize:"+pendingSize)