Your First Stream

Learn how to build your first stream in just a few minutes.

In this example, we will monitor a wallet. Specifically, we'll monitor all incoming and outgoing transactions of that wallet!

In order to use the Moralis Streams API, you can either use the SDK (programmatically) or via our UI dashboard.

Programmatically

We will use Moralis SDK to create a stream, and you can install the Moralis SDK like this:

import Moralis from 'moralis';

Moralis.start({
  apiKey: 'YOUR_API_KEY',
});

const stream = {
    address: '0x68b3f12d6e8d85a8d3dbbc15bba9dc5103b888a4' // address to monitor
    chains: [EvmChain.ETHEREUM, EvmChain.POLYGON] // list of blockchains to monitor
    description: 'monitor Bobs wallet', // your description
    network: 'evm',
    tag: 'bob', // give it a tag
    type: 'wallet' // can be wallet or contract,
    webhookUrl: 'https://YOUR_WEBHOOK_URL' // webhook url to receive events,
  }

const newStream = await Moralis.Streams.add(stream);
newStream.toJSON() // { id: 'YOUR_STREAM_ID', ...newStream }

Via WebUI

  1. Go to http://admin.moralis.io/streams/wallets/new.
  2. Click on New Address Stream.
  3. Fill out the form:
    1. Address: BOBS_WALLET
    2. Webhook URL: https://YOUR_WEBHOOK_URL
    3. Tag: bob
    4. Select Blockchain (e.g., Ethereum Mainnet)
  4. Click on Create Stream.

Mandatory Test Webhook 🚨

Whenever you create or update a stream, you will receive a test webhook.

You have to return status code 200 for the stream to start.

The test body will look like this:

{
  "abis": {},
  "block": {
    "hash": "",
    "number": "",
    "timestamp": ""
  },
  "txs": [],
  "txsInternal": [],
  "logs": [],
  "chainId": "",
  "confirmed": true,
  "retries": 0,
  "erc20Approvals": [],
  "erc20Transfers": [],
  "nftApprovals": [],
  "nftTransfers": []
}

We are Live! 🎉

Now, whenever the address you monitor is involved in an incoming or outgoing transaction, you will receive a webhook with the transaction details.

Two Webhooks for Each Event

You will receive two webhooks for each event.

The first webhook will come as soon as the transaction is included in a block and has confirmed:false. This means the block in which the event occurred still runs the risk of getting dropped because of blockchain reorganization.

The second webhook will come once the block in which the event happened has minimal chance of being dropped (the chance is never zero as it is all probabilistic). This second webhook will have confirmed:true.

Edge Cases

In rare cases, the webhook with confirmed:true may come before the one with confirmed:false; please ensure to handle this scenario on your end.


Did this page help you?