Error while trying to parse stream logs

Hi,
I have a problem while parsing logs using function defined in documentation:
const decodedLogs = Moralis.Streams.parsedLogs(webhookData);
I am using back4app as parse server. My package.json:

...
  "dependencies": {
    "@types/parse": "^3.0.4",
    "axios": "^0.27.2",
    "ethers": "^5.7.0",
    "@moralisweb3/core": "^2.7.4",
    "@moralisweb3/streams": "2.21.0",
    "moralis": "^2.21.0"
  }

My cloud function:

const Moralis = require('moralis')
const logger = require("parse-server/lib/logger").default;

Parse.Cloud.define("saveStreamLogs", async (req) => {
  try {
    const StreamLogs = Parse.Object.extend("StreamLogs");
    const newLog = new StreamLogs();
    logger.info(Moralis.Streams);
    const webhookData = req.params;
    const decodedLogs = Moralis.Streams.parsedLogs(webhookData);
    logger.info("decodedLogs", decodedLogs);
    newLog.set("value", decodedLogs[0].value || "");
    newLog.set("id", decodedLogs[0].id.toString() || "");
    await newLog.save();

    return "Created new StreamLog";
  } catch (err) {
    return `Error: ${err}`;
  }
});

And i am getting error:

2023-05-22T07:13:30.866Z - Ran cloud function saveStreamLogs for user undefined with:
Input: {“confirmed”:false,“chainId”:“0x13881”,“abi”:[{“anonymous”:false,“inputs”:[{“indexed”:true,“internalType”:“uint256”,“name”:“auctionId”,“type”:“uint256”},{“indexed”:false,“internalType”:“uint256[]”,“name”:“tokenIds”,“type”:“uint256[]”},{“indexed”:false,“internalType”:“address[]”,“name”:“winnerAddresses”,“type”:“address[]”}],“name”:“AuctionEnded”,“type”:“event”},{“anonymous”:false,“inputs”:[{“indexed”:false,“internalType”:“uint8”,“name”:“version”,“type”:“uint8”}],“name”:“Initialized”,“type”:“event”},{“anonymous”:false,“inputs”:[{“indexed”:false,“internalType”:“uint256[]”,“name”:“tokenIds”,“type”:“uint256[]”},{“indexed”:false,“internalType”:“address”,“name”:“imxNftAddress”,“type”:“address”},{“indexed”:false,“internalType”:“uint256”,“name”:“endTime”,“type”:“uint256”},{“indexed”:false,“internalType”:“contract IERC20Upgradeable”,“name”:“paymentToken”,“type”:“address”},{“indexed”:false,“internalType”:“uint256”,“name”:“price”,“type”:“uint256”},{“indexed”:false,“internalType”:“bytes32”,“name”:"… (truncated)
Result: “Error: TypeError: Cannot read property ‘parsedLogs’ of undefined”

Hi @fansanah

Try replacing the import with const Moralis = require("moralis").default;

I think that should fix the error.

Hi,
now it is working, thanks for help. :raised_hands:

1 Like