Hello, I am trying to test the Stream API but it’s giving me an error “‘Could not POST to http://localhost:4000/webhook. Please check your webhook URL.’”
Here’s my code:
import Moralis from 'moralis';
import { EvmChain } from "@moralisweb3/common-evm-utils";
import express from "express";
const Moralis2 = Moralis.default
const app = express();
const port = 4000;
app.use(express.json())
app.post("/webhook", async (req, res) => {
const webhook = req.body;
console.log(webhook)
return res.status(200).json();
})
const main = async () => {
Moralis2.start({
apiKey: "APIKEY"
});
const stream = {
chains: [EvmChain.ETHEREUM, EvmChain.POLYGON], // list of blockchains to monitor
description: "monitor Bobs wallet", // your description
tag: "bob", // give it a tag
webhookUrl: "http://localhost:4000/webhook", // webhook url to receive events,
includeNativeTxs: true
}
const newStream = await Moralis2.Streams.add(stream);
const { id } = newStream.toJSON(); // { id: 'YOUR_STREAM_ID', ...newStream }
// Now we attach bobs address to the stream
const address = "0x68b3f12d6e8d85a8d3dbbc15bba9dc5103b888a4";
await Moralis2.Streams.addAddress({ address, id });
}
app.listen(port, () => {
console.log("live")
main()
})