Sync and Watch Contract Events plugin : Event data not being registered

Hi again !

I just managed to configure the plugin and now my events are well registered within the new table !
But the data that is emitted within the event is not registered as a field. Am I supposed to retrieve this data by using the transactionIndex/logIndex or am I missing something in the configuration which is supposed to do the job ?

Hey @SachaH

Can you take a screenshot of the table with synced info? And what information do you want to receive?
Please provide an address of smartcontract and chain.

Hey @Yomoo

Here are all the informations asked:

Hey @SachaH

Try this abi:

{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_audit","type":"address"}],"name":"auditRegistered","type":"event"}

Info which it will return:

Hey,

I just replaced the abi with the one you gave for my event, I’m still getting the event and its informations, but not the data contained in it within the table

Hey @SachaH

I gave you incorrect abi :sweat_smile:
And in this case you have to do some code in cloud functions. I’ll provide you an example in 10 minutes :man_factory_worker:

Hey no worries I know how to get back the data from the event I just thought that giving the abi would allow feeding the table with the data contained in the event :wink:
I just made an after save trigger on the table given to the plugin then i apply the following logic

const { object: auditorRegisteredEvent } = request
    const events = await factoryContract.getPastEvents('auditorRegistered', {
      fromBlock: auditorRegisteredEvent.attributes.block_number,
      toBlock: auditorRegisteredEvent.attributes.block_number + 1,
    });
    const foundEvent = events.find(
      (event) => event.logIndex === auditorRegisteredEvent.attributes.log_index,
    );

    const auditorAddress = foundEvent.returnValues._auditor.toLowerCase();

Awesome work!

But for your casse the best solution is to use beforeconsume trigger.
Is it your contract? Can you please create one more event?

@SachaH I want to test prepaired code

Ah, I can do it by myself

UPDATE: No, I can’t :sweat_smile:

Hey I didn’t get what you wanted me to do, yes it is my contract, if you want to generate an event just call this method :wink: https://testnet.bscscan.com/address/0x5e192b22b5f30efd8a1897699813b7cd022ad0c0#writeContract

Hey @SachaH

There was a problem with name _auditor. Column names can’t began with symbol _. So above you can see the solution:

Moralis.Cloud.beforeConsume("TableEventName", (event) => {
  const logger = Moralis.Cloud.getLogger();
  event.auditor = JSON.stringify(event._auditor);
  return event;
});

Let nme know hot it works for you

1 Like

@SachaH

ABI:

{
  "anonymous": false,
  "inputs": [
    {
      "indexed": true,
      "internalType": "address",
      "name": "_auditor",
      "type": "address"
    }
  ],
  "name": "auditorRegistered",
  "type": "event"
}

Topic name 0x01d541ecc7e468bb4cc2794ffb6b02738b04182d627c19a490155feeaf025e03

Hey @Yomoo ,

The topic have to be hashed ? If so how did you got the topic ? from bscscan ?
Strange enough It doesn’t seem that it’s passing in beforeConsume

Moralis.Cloud.beforeConsume('EventSyncAuditorRegistered', async (event) => {
  const query = new Moralis.Query('Contract');
  query.equalTo('chainId', '0x61');
  query.equalTo('name', 'Factory');
  const [factoryContractInfos] = await query.find();

  const newEvent = {
    ...event,
    auditor: JSON.stringify(event._auditor),
  };

  await factoryContractInfos.save(
    {
      test: event,
    },
    { useMasterKey: true },
  ); // This is because my logs page is not working currently (reported in https://forum.moralis.io/t/logs-are-not-working/1315)

  return newEvent;
});

You can use not hashed name auditorRegistered(address) as well. Yes, you can find hashed topic name on bscscan.

1 Like

Does this code work?

No unfortunately it doesn’t seem the beforeConsume is triggered within my cloud function at all

Can you please try only my code and check the name of the function. You should paste the name from the database object