I need help with Moralis streams. I am trying to create a stream to listen to wallet native currency transactions. I created the webhook file and am listening through ngrok. It works fine when I create the stream from the Moralis admin panel, but when I create the stream through the script, it doesn’t listen. What is the issue, and how can I resolve it?
webhook.js
const express = require(“express”);
const app = express();
const port = 7000;
app.use(express.json());
app.post("/webhook", async (req, res) => {
console.log(“Received a webhook call”);
const { body } = req;
try {
console.log(“body”, body);
} catch (err) {
console.log(err);
return res.status(400).json();
}
return res.status(200).json();
});
app.listen(port, () => {
console.log(“Listening to Stream”);
});
index.js
const Moralis = require(“moralis”).default;
Moralis.start({
apiKey:
config.key,
});
const runApp = async () => {
const option = {
webhookUrl: “https://15ca-103-105-211-114.ngrok-free.app/webhook”, // replace with your own webhook URL
description: “My first stream”,
tag: “my_stream”,
chains: [“0x61”],
includeNativeTxs: true,
includeInternalTxs: true,
};
const newResponse = await Moralis.Streams.add(option);
const { id } = newResponse.toJSON(); // print the stream id
console.log("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>", id);
const address = [
“0x522d9256ac9Dc7Ce6bacCDeD78F2318f0A109e50,0x02a2C3ec13b3f2d9C9bFc3B78Be00bA5804276e2”,
];
await Moralis.Streams.addAddress;
({ address, id });
console.log(“Run”);
};
runApp();
New contributor
Umaid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.