-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.js
49 lines (39 loc) · 1.41 KB
/
part2.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/node
const { Web3 } = require('web3');
var quicknodeurl = 'YOUR_QUICKNODE_URL';
// Replace this with the BSC mainnet provider URL
const providerUrl = quicknodeurl
const web3 = new Web3(providerUrl);
async function getTransactionDetails(transactionHash) {
try {
const transaction = await web3.eth.getTransaction(transactionHash);
console.log('Transaction:', transaction);
} catch (error) {
console.error('Error fetching transaction details:', error);
}
}
async function getBlockTransactions(blockNumber) {
try {
const block = await web3.eth.getBlock(blockNumber);
console.log('Block Number:', block.number);
console.log('Block Transactions:', block.transactions);
for (const transactionHash of block.transactions) {
await getTransactionDetails(transactionHash);
}
} catch (error) {
console.error('Error fetching block transactions:', error);
}
}
async function fetchAllBlocks() {
try {
const latestBlockNumber = await web3.eth.getBlockNumber();
const genesisBlockNumber = 0;
for (let blockNumber = latestBlockNumber; blockNumber >= genesisBlockNumber; blockNumber--) {
console.log('Fetching block:', blockNumber);
await getBlockTransactions(blockNumber);
}
} catch (error) {
console.error('Error fetching blocks:', error);
}
}
fetchAllBlocks();