hello cryptokid I have tried several things and the first thing is that moralis changed the interface and the old api did not grab it or at least there is a new api that says default, and when I take this one, now if I get to the server the event but I have several questions, doubts arose, the first question is:
because when i try to put the api in prod
it throws me the following error:
What is the difference between production and demo? and it should take this url, right? I couldnāt swagger
and the second question would be:
How do I extract the data to mongo db with parse-server? Is there any updated or functional example that I can follow please.
with the address of ngron, this is my index.ts:
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable no-undef */
/* eslint-disable no-unused-expressions */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
/* eslint-disable prefer-const */
/* eslint-disable @typescript-eslint/no-unused-vars */
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 { streamsSync } from '@moralisweb3/parse-server';
// @ts-ignore
import { Types } from '@moralisweb3/streams';
import { parseDashboard } from "./parseDashboard";
// @ts-ignore
import { BigNumber } from '@moralisweb3/core';
// @ts-ignore
import { EvmChain } from "@moralisweb3/evm-utils";
import { marketAbi } from './abi';
// @ts-ignore
import { verifySignatures } from './utils/verifySignature'
// @ts-ignore
import { contracts, chainID } from './config/moralis-connect'
import { json } from 'envalid';
const Web3 = require('web3');
let Transfer = require("./utils/TransferSchema").Transfers;
const connectDB = require("./utils/ConectToDB").ConectToDB;
interface URI{
value: string;
id: BigNumber;
}
export const app = express();
let url = '';
const address = contracts.auction;
const web3 = new Web3()
const port = config.PORT
Moralis.start({
apiKey: config.MORALIS_API_KEY,
});
const verifySignature = (req: any, secret: any) => {
const providedSignature = req.headers["x-signature"]
if(!providedSignature) {throw new Error("Signature not provided")}
const generatedSignature= web3.utils.sha3(JSON.stringify(req.body)+secret)
if(generatedSignature !== providedSignature) {throw new Error("Invalid Signature")}
}
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
app.use(
streamsSync(parseServer, {
apiKey: config.MORALIS_API_KEY,
webhookUrl: config.STREAMS_WEBHOOK_URL
}
),
);
app.use(`/server`, parseServer.app);
app.use(`/dashboard`, parseDashboard);
app.get('/streams', async (req: any, res: any) => {
try {
const response = await Moralis.Streams.getAll({limit: 0});
console.log(response.raw);
} catch (e) {
console.error(e);
}
})
app.listen(port, () => {
console.log('escuchando streams')
})
app.post("/AuctionCreated", async (req: any, res: any) => {
try {
console.log("STREAMS_WEBHOOK_URL", `${url}${config.STREAMS_WEBHOOK_URL}`);
const webHookUrl = `${url}${config.STREAMS_WEBHOOK_URL}`;
const chaindIdFinal = chainID.testNet;
const stream = await Moralis.Streams.add({
chains: [EvmChain.MUMBAI],
description: 'AuctionsCreated721',
tag: 'AuctionsCreated',
abi: marketAbi,
includeContractLogs: true,
topic0: [
'AuctionCreated(address,uint256,uint8,uint256,uint256,uint256,address)'
],
webhookUrl: webHookUrl,
});
const { id } = stream.toJSON();
await Moralis.Streams.addAddress({
address,
id
});
} catch (e) {
console.log("Not Moralis", e);
}
return res.send('ok');
})
const httpServer = http.createServer(app);
httpServer.listen(port, async () => {
if (config.USE_STREAMS) {
// eslint-disable-next-line no-console
console.log(
`Moralis Server is running on port ${port} and stream webhook url ${config.STREAMS_WEBHOOK_URL}`,
);
} else {
// eslint-disable-next-line no-console
console.log(`Moralis Server is running on port ${port}.`);
}
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
I also get an error for the listen:
error: undefined {"address":"::","code":"EADDRINUSE","errno":-4091,"port":1337,"syscall":"listen"}