-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (25 loc) · 1.2 KB
/
Copy pathapp.js
File metadata and controls
33 lines (25 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const Web3 = require('web3');
const config = require('./config');
const dexRouterAddresses = ['0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D','0x10ED43C718714eb63d5aA57B78B54704E256024E','0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F']
web3 = new Web3(new Web3.providers.HttpProvider(config.evmNodeLink));
web3Ws = new Web3(new Web3.providers.WebsocketProvider(config.evmWSNodeLink));
async function main() {
try {
web3Ws.onopen = function(evt) {
web3Ws.send(JSON.stringify({ method: "subscribe", topic: "transfers"}));
console.log('connected')
}
subscription = web3Ws.eth.subscribe('pendingTransactions', function (error, result) {
}).on("data", async function (transactionHash) {
let transaction = await web3.eth.getTransaction(transactionHash);
if (transaction != null && (dexRouterAddresses.includes(transaction['to']) || dexRouterAddresses.includes(transaction['from'])))
{
console.log(transaction,'------------');
}
})
} catch (error) {
console.log('failed to fetch mempool data:')
process.exit();
}
}
main();