Hey guys,
I am trying to destructure the Moralis stream using the following function:
export function parseEventData(req: any) {
try {
const updates: any = {};
for (const log of req.body.logs) {
const abi = req.body.abis[log.streamId];
if (abi) {
const { filter, update, eventName } = realtimeUpsertParams(abi, log, req.body.confirmed, req.body.block);
return { data: update, tagName: log.tag, eventName };
}
}
} catch (e: any) {
console.log(e);
}
}
This function gives me the following error:
TypeError: Cannot destructure property 'data' of '(0 , utils_1.parseEventData)(...)' as it is undefined.
I get the error when I use the function over here:
app.post("/webhook", async (req, res) => {
console.log(req.body)
console.log("Handled!")
res.send('Webhook response')
res.status(200).end()
try {
verifySignature(req, config.MORALIS_API_KEY);
const { data, tagName, eventName }: any = parseEventData(req);
console.log(data);
await parseUpdate(`SFS_${eventName}`, data);
} catch (e) {
console.log(e);
}
res.send('ok');
});
It seems like I have left some param undefined, however I’m having a hard time figuring out exactly which one.
EDIT: I found the following function on the Moralis Streams docs:
interface MyEvent {
from: string;
to: string;
}
const decodedLogs = Moralis.Streams.parsedLogs<MyEvent>({ webhook, tag });
decodedLogs[0]; // { from: '0x...', to: '0x...' }
Is it possible for me to use this instead of the above 2 functions? If so, is there an example of this function being used?
Thanks!