Skip to content

Instantly share code, notes, and snippets.

@itsanishjain
Last active February 12, 2024 10:48
Show Gist options
  • Save itsanishjain/8cb891b3232bb94ec5863289ff751059 to your computer and use it in GitHub Desktop.
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.
"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