Created
April 19, 2023 23:41
-
-
Save 0xlxy/586eefd40b0307d61c508d6d1ae2895f to your computer and use it in GitHub Desktop.
Ethereum Blockchain Indexer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { ethers } = require("ethers"); | |
const provider = new ethers.providers.WebSocketProvider( | |
"wss://mainnet.infura.io/ws/v3/992c9dccdfd849dabf68ab78d689595d" | |
); | |
console.log(provider); | |
provider.on("block", (blockNumber) => { | |
provider | |
.getBlockWithTransactions(blockNumber) | |
.then((block) => { | |
const transactions = block.transactions; | |
console.log( | |
`New block received: ${blockNumber}, ${transactions.length} transactions` | |
); | |
console.log(transactions); | |
}) | |
.catch((error) => { | |
console.error(error); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "block-indexer", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"ethers": "^5.7.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment