This is my addStream code:
const Moralis = require("moralis").default
const {EvmChain} = require("@moralisweb3/evm-utils")
// const { headers, body } = request;
async function main() {
Moralis.start({
apiKey: 'config.MORALIS_API_KEY',
});
const whoopyCreatedAbi = [{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "instance",
type: "address"
},
{
indexed: true,
internalType: "address",
name: "creator",
type: "address"
}
],
name: "NewClone",
type: "event"
}]
const options = {
chains: [EvmChain.MUMBAI], // Ethereum Name Service so we only monitor Ethereum
description: "Created Whoopys", // your description
tag: "whoopyCreated", // give it a tag
abi: whoopyCreatedAbi,
topic0: ["NewClone(address,address)"],
includeContractLogs: true,
webhookUrl: "http://EDITEDOUT-.in.ngrok.io/webhook", // webhook url to receive events,
};
const stream = await Moralis.Streams.add(options)
await Moralis.Streams.addAddress({
id: stream.id,
address: "0x24290447ee215bb2565F53e1c6092BA8b1fhr75y"
})
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
The is my index.js:
import Moralis from 'moralis';
import express from 'express';
import cors from 'cors';
import config from './config';
import { parseServer } from './parseServer';
// @ts-ignore
import ParseServer from 'parse-server';
import http from 'http';
import verifySignature from './helpers/utils'
export const app = express();
Moralis.start({
apiKey: config.MORALIS_API_KEY,
});
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
app.use(`/server`, parseServer);
app.post("/webhook", (req, res) => {
console.log(req.body) // Call your action on the request here
console.log("Handled!")
res.status(200).end() // Responding is important
})
const httpServer = http.createServer(app);
httpServer.listen(config.PORT, () => {
// eslint-disable-next-line no-console
console.log(`Moralis Server is running on port ${config.PORT}.`);
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);