Created
March 14, 2023 15:41
-
-
Save snowkidind/86e83e92ee3fc0ddd1eb8360745fea79 to your computer and use it in GitHub Desktop.
Connect to erigon websocket and filter by some addresses you want to watch.
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 wsProvider = new ethers.providers.WebSocketProvider("http://YOURWSURLHERE") | |
// these are most popular addresses, note all lower cased | |
const watchList = [ | |
"0xdac17f958d2ee523a2206206994597c13d831ec7", // USDT | |
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH | |
"0x7a250d5630b4cf539739df2c5dacb4c659f2488d", // Uniswap V2: Router 2 | |
"0xea674fdde714fd979de3edf0f56aa9716b898ec8", // Ethermine | |
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC | |
"0xa2327a938febf5fec13bacfb16ae10ecbc4cbdcf", // FiatTokenV2_1 | |
"0xa090e606e30bd747d4e6245a1517ebe430f0057e", // Coinbase: Miscellaneous | |
"0x5b3256965e7c3cf26e11fcaf296dfc8807c01073", // opensea.eth | |
"0xa5409ec958c83c3f309868babaca7c86dcb077c1", // OpenSea: Registry | |
"0xf9e266af4bca5890e2781812cc6a6e89495a79f2", // AuthenticatedProxy | |
"0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be", // Binance | |
"0x7be8076f4ea4a4ad08075c2508e481d6c946d12b", // OpenSea: Wyvern Exchange v1 | |
"0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5", // Nanopool | |
"0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45", // Uniswap V3: Router 2 | |
"0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208", // IDEX | |
"0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98", // Bittrex | |
"0x6b175474e89094c44da98b954eedeac495271d0f", // DAI | |
"0x0b95993a39a363d99280ac950f5e4536ab5c5566", // Binance: Contract | |
"0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0", // EOS | |
"0x28c6c06298d514db089934071355e5743bf21d60", // Binance 14 | |
"0x06012c8cf97bead5deae237070f9587f8e7a266d", // CK | |
"0x3cd751e6b0078be393132286c442345e5dc49699", // Coinbase 4 | |
"0xd34da389374caad1a048fbdc4569aae33fd5a375", // Genesis Mining | |
"0xb5d85cbf7cb3ee0d56b3bb207d5fc4b82f43f511", // Coinbase 5 | |
"0x1ad91ee08f21be3de0ba2ba6918e714da6b45836" // Hiveon Pool | |
] | |
const onWatchList = (address) => { | |
if (!address) return false | |
for (let i = 0, len = watchList.length; i < len; i++) { | |
if (address && address.toLowerCase() === watchList[i]) { | |
return true | |
} | |
} | |
return false | |
} | |
const listen = () => { | |
// new pending transaction | |
wsProvider.on("pending", (hash) => { | |
wsProvider.getTransaction(hash).then((tx) => { | |
if (!tx) return | |
if (onWatchList(tx.from) || onWatchList(tx.to)) { // all these populars are smart contracts, more likely to show up in to's | |
console.log(tx) | |
} | |
}) | |
}) | |
wsProvider._websocket.on("error", async () => { | |
console.log(`Socket Error. Attempting reconnect in 10s...`) | |
setTimeout(listen, 30000) | |
}) | |
wsProvider._websocket.on("close", async (code) => { | |
console.log(code) | |
wsProvider._websocket.terminate() | |
}) | |
} | |
;(() => { | |
listen() | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment