Skip to main content
Let’s create a stream that monitors specific CryptoPunk NFTs based on an array of Token IDs.

Programmatically

JavaScript
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
});
Python
from moralis import streams

api_key = "YOUR_API_KEY"

punk_transfer_abi = [{
  "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",
}]

body = {
    "webhookUrl": "https://YOUR_WEBHOOK_URL",
    "description": "1000 to 1002 cryptopunks",
    "tag": "cryptoPunks",
    "topic0": ["PunkTransfer(address,address,uint256)"],
    "includeContractLogs": True,
    "abi": punk_transfer_abi,
    "advancedOptions": [
      {
        "topic0": "PunkTransfer(address,address,uint256)",
        "filter": { "in": ["punkIndex", ["1000", "1001", "1002"]] },
        "includeNativeTxs": True,
      },
    ],
    "chainIds": ["0x1"],
}

result = streams.evm.create_stream(
    api_key=api_key,
    body=body,
)

print(result)

Via WebUI

  1. Create a new Stream
  2. Fill out the form
  3. Switch on Event Emittance and Add the Abi and select the topic
  4. Add below value to advanced options
[
  {
    "topic0": "PunkTransfer(address,address,uint256)",
    "filter": { "in": ["punkIndex", ["1000", "1001", "1002"]] }
  }
]
  1. Click on create stream button