-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
33 lines (24 loc) · 942 Bytes
/
index.js
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
33
const { ethers } = require('ethers');
async function fetchEVMBlockFor(provider, blockNumber) {
try {
const block = await provider.getBlockWithTransactions(blockNumber);
const transactions = block?.transactions || [];
console.log('block n°', blockNumber, 'data => txCount:', transactions.length);
console.log('< ' + blockNumber + ' > start check if addresses are contracts for block n°', blockNumber);
transactions.map(async (tx) => provider.getCode(tx.from));
console.log('< ' + blockNumber + ' > end check if addresses are contracts');
} catch (err) {
console.error('fetch blocks n°' + blockNumber, err);
}
}
async function startWebsocket() {
let wsProvider = new ethers.providers.WebSocketProvider(process.env.PROVIDER_URL);
console.log('websocket connected');
wsProvider.on('block', async (blockNumber) => {
fetchEVMBlockFor(wsProvider, blockNumber);
});
}
function init() {
startWebsocket();
}
init();