Last active
February 12, 2024 10:48
-
-
Save itsanishjain/8cb891b3232bb94ec5863289ff751059 to your computer and use it in GitHub Desktop.
How to utilize the Alchemy WebSocket to subscribe to and monitor Ethereum transactions for users.
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
"use client"; | |
import { Network, Alchemy } from "alchemy-sdk"; | |
import { ethers } from "ethers"; // ethers V6 | |
const settings = { | |
apiKey: "", // Replace with your Alchemy API Key. | |
network: Network.MATIC_MAINNET, // Replace with your network. | |
}; | |
const alchemy = new Alchemy(settings); | |
export default function AlcmenyWebsocket() { | |
const filter = { | |
address: "USER_ADDRESS", | |
topics: [ethers.id("Transfer(address,address,uint256)")], | |
}; | |
alchemy.ws.on(filter, (log, event) => { | |
console.log({ log }, { event }); | |
}); | |
return <div className="text-xl text-center">Alcmeny Websocket</div>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment