Start smart contract event sync job from cloud code

I need to be able to start watching events from cloud code programmatically and start and stop listening depending on some logic. There is a moralis plugin which you need to manually initiate and set up the smart contract to whom events to watch. Can we initiate the same process through cloud code?

2 Likes

Similar issue here.

My contract creates contracts and I’d like to listen for events that those created contracts are emitting. Is there a way to programatically set up an event sync with a given contract ?

there is an option to add a sync for an event with moralis-admin-cli command
https://docs.moralis.io/moralis-server/tools/moralis-admin-cli#add-contract

Yep, that would be something. But this must run in the client browser.

User1 Action =>

contract X created & new UI element appears on User1 screen.

User2 interacts with the contract X

=> User1 screen should update.

This only works if the client side js can trigger an event sync to a specific contract.

moralis-admin-cli must run in a secure env, not in the end user’s browser :slight_smile:

So the only solution I see right now is to run a separate REST endpoint, which can take POST requests with the address of every new contract X that is created.

There on this server you could have a script triggered which runs

moralis-admin-cli add-contract …

But Ivan replied on discord that they may soon add a feature to solve our issue simply and quickly. Like everything Moralis :smiley:

any news about this?

you can sync a contract event from code now:

https://docs.moralis.io/moralis-dapp/connect-the-sdk/connect-using-node#add-new-event-sync-from-code