Sync and Watch Address

I am building an app that allows users to enter an address to watch and set alerts to when tx takes place after this Moralis tutorial series https://www.youtube.com/watch?v=-M1GR45GykQ&t=4s

The problem is that the Plugin is no longer to be installed. I’ve seen the message that states:
“The Sync Address and Contract Events can now be found on the server by clicking View Detail and selecting the Sync tab”, but I wanna do it programmatically.

In the tutorial, this plugin added 2 more table object in the DB, the “WatchEthAddress” and “EthTransactions”.

I’ve also read the other topics on this forum like this one Sync and Watch Address in Dapp (Possible?) but they don’t help me in this case.

You can sync and watch the address programmatically with cloud code in this way

const results = await Moralis.Cloud.run("watchBscAddress", {
  address: "0x...",
  sync_historical: true,
});

Check this doc for more info
https://docs.moralis.io/moralis-dapp/automatic-transaction-sync/historical-transactions#watch-address-from-code

Tried it and I got this errors.

You need to add it to the cloud code function and call the cloud function from your app.

you will also have to add useMasterKey parameter

Yes, I did that. So my cloud function is this one:
image

and I call this like:

    const address = "0x2E8791510312942F79530A2C25cd47768425caAd";
    const result = await Moralis.Cloud.run("watchAddress", { address });

and that error pops up.

you have to add {useMasterKey: true} to that code,
for example:

        const results = await Moralis.Cloud.run("watchEthAddress", {address: address, sync_historical: false}, {useMasterKey: true})
1 Like

It worked, thanks!
One more thing, the tutorial I posted above is outdated and people will only search for answers, maybe do another? In addition, what is in the tutorial is way off with what is on the Github page of the video description.

The syntax changed over time.