Track Specific CryptoPunk NFTs by Token IDs
Lets create a stream that monitor specific CryptoPunk NFTs based on an array of Token IDs.
Programmatically​
- JavaScript
- Python
const punkTransferAbi = [
{
anonymous: false,
inputs: [
{ indexed: true, name: "from", type: "address" },
{ indexed: true, name: "to", type: "address" },
{ indexed: false, name: "punkIndex", type: "uint256" },
],
name: "PunkTransfer",
type: "event",
},
]; // valid abi of the event
const options = {
chains: [EvmChain.ETHEREUM], // list of blockchains to monitor
description: "1000 to 1002 cryptopunks", // your description
tag: "cryptoPunks", // give it a tag
abi: punkTransferAbi,
includeContractLogs: true,
topic0: ["PunkTransfer(address,address,uint256)"], // topic of the event
advancedOptions: [
{
topic0: "PunkTransfer(address,address,uint256)",
filter: { in: ["punkIndex", ["1000", "1001", "1002"]] }, // only receive transfer events if the token id is 1000/1001/1002
includeNativeTxs: true,
},
],
webhookUrl: "https://YOUR_WEBHOOK_URL", // webhook url to receive events,
};
const stream = await Moralis.Streams.add(options);
const { id } = stream.toJSON(); // { id: 'YOUR_STREAM_ID', ...stream }
// Attach the contract address to the stream
await Moralis.Streams.addAddress({
id,
address: "0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB", // crypto punks address
});
from moralis import streams
api_key = "YOUR_API_KEY"
punkTransferAbi = [{
"anonymous": false,
"inputs": [
{ "indexed": true, "name": "from", "type": "address" },
{ "indexed": true, "name": "to", "type": "address" },
{ "indexed": false, "name": "punkIndex", "type": "uint256" },
],
"name": "PunkTransfer",
"type": "event",
}]; // valid abi of the event
body = {
"webhookUrl": "https://YOUR_WEBHOOK_URL",
"description": "1000 to 1002 cryptopunks",
"tag": "cryptoPunks",
"topic0": ["PunkTransfer(address,address,uint256)"],
"includeContractLogs": True,
"abi": punkTransferAbi,
"advancedOptions": [
{
topic0: "PunkTransfer(address,address,uint256)",
filter: { "in": ["punkIndex", ["1000", "1001", "1002"]] }, // only receive transfer events if the token id is 1000/1001/1002
includeNativeTxs: True,
},
],
"chainIds": ["0x1"],
}
result = streams.evm.create_stream(
api_key=api_key,
body=body,
)
print(result)
Via WebUI​
- Create a new Stream
- Fill out the form
- Switch on Event Emittance and Add the Abi and select the topic
- Add below value to advanced options
[
{
"topic0": "PunkTransfer(address,address,uint256)",
"filter": { "in": ["punkIndex", ["1000", "1001", "1002"]] }
}
]
- Click on create stream button.