Inbuilt parse data method from streams API is not working correctly

The inbuilt parse data utility from streams API is not working correctly. It always returns a key-value pair as a response where the key is the event parameter name and the value is undefined.

This is the actual event received from streams API

{
  confirmed: false,
  chainId: '0x13881',
  abi: [
    {
      anonymous: false,
      inputs: [Array],
      name: 'ItemAdded',
      type: 'event'
    }
  ],
  streamId: 'fb6d5dc8-fecf-4490-a97a-508d6e85f38d',
  tag: 'WEB_2_ADD_ITEM_DEVELOPMENT',
  retries: 0,
  block: {
    number: '29179789',
    hash: '0x4ffd57f49cf3c0ceef515085599859639632275c14128c30aa8bdecb1a657fb8',
    timestamp: '1668588427'
  },
  logs: [
    {
      logIndex: '127',
      transactionHash: '0xa5123fccdfbaad40715a9450c843e03e815c2e75de35ae69d7d593a0669e17db',
      address: '0x450dab417e18f4dd9df17643a5e145045c5ba0ed',
      data: '0x',
      topic0: '0x78d68ba0e8c23b92e7c700d99efed2719520cbd4af845b2c03ae251f9cdf3d52',
      topic1: '0x000000000000000000000000000000000000000000000000000000000000001a',
      topic2: '0xab1ec0c17fb623104278a13673518d4573282c563574a2f550724be95c794a15',
      topic3: null
    }
  ],
  txs: [],
  txsInternal: [],
  erc20Transfers: [],
  erc20Approvals: [],
  nftApprovals: { ERC1155: [], ERC721: [] },
  nftTransfers: []
}

When parsing with the parse data function, it doesn’t parse it properly

[ { itemId: undefined, itemName: undefined } ]

how do you use that inbuilt parse data utility? from what repo?

if you are using moralis sdk, what version?

Yes, we are using the parseLogs method from the SDK

SDK version:

"moralis": "^2.7.2",

Usage:

interface ItemEvent {
  itemId: BigNumber;
  itemName: string;
}

const decodedLogs = Moralis.Streams.parsedLogs<ItemEvent>(webhookData);

This is the actual inputs array you get? Where did you copy this webhook sample from or how was that logged?

No, I guess that input is not completely printed in the console, it’s just short-printed the value I guess. This webhook was made for POC against my own contract and I copied this value by consoling the webhook data received from streams

what happens, any error?

read it again, no error but those undefined values

can you try with latest version that is 2.7.4?

I’m also pasting the abi here:

     "abi": [
        {
          "anonymous": false,
          "inputs": [
            {
              "indexed": true,
              "internalType": "uint256",
              "name": "itemId",
              "type": "uint256"
            },
            {
              "indexed": true,
              "internalType": "string",
              "name": "itemName",
              "type": "string"
            }
          ],
          "name": "ItemAdded",
          "type": "event"
        }
      ]
1 Like

this will not be a string if you have this in the abi:

            {
              "indexed": true,
              "internalType": "string",
              "name": "itemName",
              "type": "string"
            }

it will be the hash of the string,

in your particular case it will be this value:

topic2: '0xab1ec0c17fb623104278a13673518d4573282c563574a2f550724be95c794a15',

You are right it will be hash, but at least the hash should be parsed properly right ?

Conversion of the hash is beacuse of the indexed parameter but it will be considered as string in ABI.

from the abi is should know that it is a hash from that

Correct, It is hash but it should at least parse the value as hash right? instead of undefined.

The expected output should be

{
    itemName: "<hash>",
    itemId: "<number>",
}

I have tried with the Moralis SDK version 2.7.4 also, same behavior.

I’m not familiar with that syntax. You can look in the sdk code to see what happens. Or you can parse it directly with ethers.

You can try something similar as here to parse it with ethers

1 Like

I wonder if anyone was able to decode multiple event logs, and differentiate their event name, default parseLogs seems to be only decoding the event arguments