Is there a way to programmatically add a new "Sync and Watch Contract Events"?

  1. Is there a way to programmatically add a new “Sync and Watch Contract Events”?

syncWatchContract({chainID : 1234, topic: “…”, abi : “…”, contract: “0x…”, syncHistorical:true}

  1. Also, can I watch multiple contracts with the same ABI + same topic to track within the same Class “table”?


you can do it from CLI

we will expose API for this soon too

Thanks! Can I make these calls from the “Cloud Functions” ?

I discovered that we have a way to do it from cloud function

There is also a Cloud Function which can be called from Cloud Functions or even the front end:

that’s the watchAddress function. Can that be altered for “sync and watch Contract Events” ?

I’m hoping for the Cloud Function equivalent of this…

got it, we will add a way in the next few weeks, unfortunately currently we only have CLI

1 Like

Hi @ivan , Is this feature already implemented?


Hi Moralis users,
Hi @mayjer,

I would like to programmatically add a new “Sync and Watch Contract Events”. My app is deploying a contract for each collection that the user creates, and I would like to sync with the contracts that the users instantiate
Is this feature implemented?


To watch an address you could do:"watchEthAddress", {address, "sync_historical":true}), but this is not what you are interested in.

It may also be possible to add data directly in mongo db programmatically to set that watch for an event. You could look on how a watch event is saved in mongo db now, and add a similar entry programmatically.

Thanks @cryptokid.

How can I analyse how a watch event is saved in mongo db?

You can look in EventSync table, but meanwhile I found out that moralis-admin-cli can also add a sync for an event with add-contract parameter.
It may be easier for you to use moralis-admin-cli.

1 Like

@cryptokid I read in one thread that adding “sync and watch contract event” plugins dynamically at run-time is not currently supported because the server instance needs to be restarted for new plug-ins to take effect. The thread is from May, so maybe the situation changed. are you able to tell me if I use CLI every time I add a “sync and watch contract event” the server will restart?

In the thread mayer suggests adding the “sync” without address. Even though the risk of collision can be mitigated, I am afraid of possible attacks and it will be a vulnerability if anyone can insert data in the database table without proper validation.


I also tried to insert in the EventSync table the event programmatically. The row was added to the table, however, it doesnt take effect, so the events are not synced

I didn’t test it yet with CLI to know for sure if it requires a restart or not for the server in order to work.

ok, @cryptokid . I would like to test it. How can I know after using the CLI if the server restarted or not?

If the event starts to sync in DB after you use the CLI, then everything is ok and you don’t have to do anything else (you can test this part first)

1 Like