Last active
March 11, 2023 11:17
-
-
Save thatguyintech/b525ea093cc4d624f61927392db834cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// watch-for-mints.js | |
// npm install @alch/alchemy-web3 | |
const { createAlchemyWeb3 } = require("@alch/alchemy-web3"); | |
// TODO: Replace this with your key. | |
const alchemyApiKey = "your api key"; | |
// NFT mints emit Transfer events with "from" set to 0x0. | |
// This is the "transfer event" topic we want to watch. | |
const mintTopic = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"; | |
// This is the "from address" we want to watch. | |
const zeroTopic = "0x0000000000000000000000000000000000000000000000000000000000000000"; | |
// This is the NFT contract we want to watch. | |
const nftContractAddress = "0xbd34d145fcfd3992a0def1057891d51339a90128"; | |
// Initialize alchemy-web3 object. | |
// Docs: https://docs.alchemy.com/alchemy/documentation/subscription-api-websockets | |
const web3 = createAlchemyWeb3( | |
`wss://eth-rinkeby.ws.alchemyapi.io/ws/${alchemyApiKey}` | |
); | |
// Create the log options object. | |
const hackrDaoMintEvents = { | |
address: nftContractAddress, | |
topics: [mintTopic, zeroTopic] | |
} | |
// TODO: Add whatever logic you want to run upon mint events. | |
const doSomethingWithTxn = (txn) => console.log(txn); | |
// Open the websocket and listen for events! | |
web3.eth.subscribe("logs", hackrDaoMintEvents).on("data", doSomethingWithTxn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment