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();