获取某一个pool成交记录的web3.eth函数
时间: 2024-06-09 10:07:10 浏览: 162
你可以使用web3.eth.getPastLogs函数来获取某个池子的成交记录。其中,你需要提供该池子的合约地址和event的ABI(事件的规范描述)。
以下是一个示例代码:
```
const Web3 = require('web3');
const web3 = new Web3('https://mainnet.infura.io');
const poolAddress = '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'; // Uniswap V2 ETH/USDT pool address
const poolAbi = [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Swap","type":"event"}];
web3.eth.getPastLogs({
address: poolAddress,
fromBlock: 'latest',
toBlock: 'latest',
topics: [web3.utils.sha3('Swap(address,uint256,uint256,uint256,uint256,address)')],
abi: poolAbi
}).then((logs) => {
console.log(logs);
});
```
在这个示例代码中,我们使用了Uniswap V2 ETH/USDT池子的地址和Swap事件的ABI来获取成交记录。你可以根据你所使用的池子和事件ABI来修改这个示例代码。
阅读全文