[SOLVED] How to use core_addEventsSync?

Hey guys,

I have a factory contract which instantiates other contracts, and I need to watch out for events on those new instantiated contracts. I am currently doing this in my cloud code, however as far as I understand, every tablename has to be different, so after instantiating the first contract, I will not be able to create more events to watch.

As per this answer: Unable to save multiple contract addresses/events to a single table

@cryptokid has suggested writing new table-names in another table, and then proccessing new events using jobs. I am wondering how exactly to do this in a dynamic manner??

Also , it is mentioned to use ‘core_addEventsSync’ to sync all events in the same table. I didn’t really understand this part. When exactly am I supposed to use the following syntax:

Moralis.Cloud.run(“coreservices_addEventSync”, options, { useMasterKey: true });

Am I supposed to use it after the “watchContractEvent” function or is there another way to use it? Also, if I use ‘core_addEventsSync’, does that mean that I no longer have to use jobs to process events or do I still have to do that?

Thanks!

NOTE: The contract factory will be creating new instances of the contract automatically, so I would require everything to take place. dynamically in cloud code.

it is possible to do that, coreservices_addEventSync is somehow equivalent with watchContractEvent.

that is the old way to do it, now you can look on how to use Streams API, as we will be moving towards using Streams API, moralis.io/streams

Yes, I will be moving to the stream API soon, just waiting for a bit more clarity on how to use it as well as a tutorial on setting up the parse server with streams, etc.

So just to be clear, how exactly should I use coreservices_AddEventSync? Should I use it after using watchContractEvent or do I not need to use watchContractEvent at all? Also, does coreservices_AddEventSync solve the table name issue?

you use coreservices_AddEventSync instead of watchContractEvent, but you have to know exactly what parameters to use and you have too skip the address parameter

you can use Streams API without parse server too, you can use it with your own backend

If I skip the address parameter, how will it know what address to monitor? Also will look into using Streams on my backend.

It will monitor any address, that is the idea, all the events for that topic will go to the same table

Awesome. Checking it out now.

@cryptokid this worked like magic.

1 Like