Streams (Syncs)

This guide will teach you how to set up streams for your self-hosted Moralis Server

Overview

This guide will teach you how to set up Streams on your self-hosted Moralis Server.

Using Streams, you can listen to real-time on-chain events and automatically synchronize incoming data with your database.

Streams is what you need to replace the old Moralis-hosted Syncs:

Configuration

Open src/index.ts and make sure that streamsSync method gets config.STREAMS_WEBHOOK_URL as a webhookUrl parameter:

//........

//Set up streamSync
app.use(
  streamsSync(parseServer, {
    apiKey: config.MORALIS_API_KEY,
    webhookUrl: config.STREAMS_WEBHOOK_URL,
  })
);

//.........

You can modify this parameter in your .env file by setting STREAMS_WEBHOOK_URL to a different string value. By default it's:

STREAMS_WEBHOOK_URL = '/streams-webhook'

If you want to modify the ability to listen to Streams you can do so on your .env file by setting USE_STREAMS to true or false.

Build and run

We need to build and run the project to get the full Streams Webhook URL that we'll use later.

Build the project:

npm run build

And then run it locally:

npm run start

After starting your server you shoud see a similar message on your terminal. The message will contain the Streams Webhook URL (powered by ngrok) you will use to create a Stream:

Moralis Server is running on port 1337 and stream webhook url https://ba50-137-101-196-66.ngrok.io/streams-webhook

Create a Stream

To create a Stream, head over to the following guide or follow our YouTube tutorial from minute 7:05.

You will need to provide the Streams Webhook URL you got in the previous step:

Last updated