Moralis.EvmApi.events.getContractEvents returns empty data

Hi, i can successfully query my contract’s events using the test endpoint here:

i provide my event’s ABI, contract address and other params and the data item for each event comes back populated as expected.

When I call the SDK function from my own node script, i receive the same events (same envelope data such as block_number etc) but the data object is empty: {}.

i have confirmed that the supplied ABI is the same in both cases.

any idea why this might be happening?

one thing worth pointing out is that the generated Node.js code did not work when imported directly: the options object was not as the SDK expected (e.g. it expected an abi item whereas the generated code placed the ABI items directly into the options object i.e. not contained within an ‘abi’ field).

i am on the free plan. i have checked i have CU remaining.

i wonder, is it possible that the 300 daily streams records for the free plan could result in empty data here?

many thanks for any help :slight_smile:

Hi @wccc

Can you share your contract ABI, chain and contract address so it will be possible for us to test it.

You can also get empty data if you either the abi or topic0 is not correct.

hi,

here you go:

contract
0xA41f28031d1165cD45c69E6AB9ba2A8BE0201008

event
0x226357a480bcab31fbd8f2663fe2a14c625d8bab5c1cc23f15afe0b914732cdf

event abi:
{“anonymous”:false,“inputs”:[{“indexed”:true,“internalType”:“address”,“name”:“hatcher”,“type”:“address”},{“indexed”:true,“internalType”:“uint256”,“name”:“tokenId”,“type”:“uint256”}],“name”:“Hatched”,“type”:“event”}

Hi @wccc

It seems like I can see the data now. I have tested it with the same data which you shared.

Can you confirm if it is working now for you?

hi @johnversus, i’m still getting the same issue. could you share the code you’re using pls? thanks

Hi @wccc

I have tested it directly from the docs. Doce also provides you with the code related to it.

Let us know if you still have any issues while testing with your API key from the docs.

Hi @johnversus, thanks for getting back to me.

Yes, this is exactly the problem: it works when I test directly from the docs too, but the generated code does not work for me. Are you able to get event data from a node script/app? When using the SDK, I do get a response (after fixing the generated code - I guess the docs are out of date with the SDK), which looks like:

{"chain":"0x1","address":"0xa41f28031d1165cd45c69e6ab9ba2a8be0201008","blockHash":"0xcca7fb3a786c7749ab6de825f2c12a718ac48d86fb490500318765e66d8102fd","blockNumber":"17072863","blockTimestamp":"2023-04-18T10:04:47.000Z","transactionHash":"0xf7f8f544607ed22d4438d2ab1350887a3f21c54ddec337890d2ff157b6a0ac88","data":{}}

As you can see, the SDK is picking up the correct envelope date (chain, blockNumber etc); however, the data property is empty, whereas when I query using the docs, it is populated correctly.

Thanks again!

Here is my code.

When we try to log the entire result in console it might not show the nested json’s due its lenght. So I have added console.log to print the data object in console.

const Moralis = require("moralis").default;
require("dotenv").config();

const init = async () => {
  if (!Moralis.Core.isStarted) {
    await Moralis.start({
      apiKey: process.env.API_KEY,
    });
  }
  try {
    const response = await Moralis.EvmApi.events.getContractEvents({
      chain: "0x1",
      topic:
        "0x226357a480bcab31fbd8f2663fe2a14c625d8bab5c1cc23f15afe0b914732cdf",
      address: "0xA41f28031d1165cD45c69E6AB9ba2A8BE0201008",
      abi: {
        anonymous: false,
        inputs: [
          {
            indexed: true,
            internalType: "address",
            name: "hatcher",
            type: "address",
          },
          {
            indexed: true,
            internalType: "uint256",
            name: "tokenId",
            type: "uint256",
          },
        ],
        name: "Hatched",
        type: "event",
      },
    });

    console.log(response.raw);
    response.raw.result.forEach((e) => {
      console.log(e.data);
    });
  } catch (e) {
    console.error(e);
  }
};

init();

Please check if you can see the data using this code