使用hardhat
或者ethers.js
:
import { ethers } from "hardhat";
async function listen() {
const provider = ethers.getDefaultProvider("http://localhost:8545");
provider.on("pending", async (tx) => {
console.log("tx detected: ", tx);
})
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
listen().catch((error) => {
console.error(error);
process.exitCode = 1;
});
這樣就能得到正在pending中的tx了,如:
你就可以得到相關信息秦士,比如得到
gasPrice
缺厉,那我們就可以自建新交易超出這個gasPrice
,來進行搶先交易隧土。