[SOLVED] Failing watchContractEvent

Hi,

I am attempting to setup an event sync via a node script but getting { success: false } as response.

Here is the script that I’m using:

require('dotenv').config()

const Moralis = require("moralis-v1/node");

const serverUrl = process.env.MORALIS_SERVER_URL;
const appId = process.env.MORALIS_APP_ID;
const masterKey = process.env.MORALIS_MASTER_KEY;

const cmdArgs = process.argv.slice(2);

if(!cmdArgs[0]) {
    throw Error("Contract address not provided");
}

const watchContractEvents = async () => {
    await Moralis.start({ serverUrl, appId, masterKey });
    
    let options = {
        chainId: "0x89",
        address: cmdArgs[0],
        topic: "TokenMinted(uint256, address)",
        abi: {
            anonymous: false,
            inputs: [
                {
                    indexed: false,
                    internalType: "uint256",
                    name: "tokenId",
                    type: "uint256"
                },
                {
                    indexed: false,
                    internalType: "address",
                    name: "minter",
                    type: "address"
                }
            ],
            name: "TokenMinted",
            type: "event"
          },
        limit: 500000,
        tableName: "TokenMintedEvents",
        sync_historical: false,
    };

    let moralisRun = await Moralis.Cloud.run("watchContractEvent", options, { useMasterKey: true })
    console.log('moralisRun:', moralisRun);
};

watchContractEvents();

I’ve tried specifying the topic in hex format, but it result in the same failure. Hopeful that there’s something glaringly obvious that I’m missing.

Thanks in advance,
Yuri

I don’t see something obvious at a first look. does it work if you try to add it from the admin interface?

Maybe try to use console.log with the parameters from options to see if everything looks like expected

Yes, I set up a sync form the dashboard and it works as expected.

Get this in the dashboard logs:

2022-09-12T17:57:07.985Z - Ran cloud function watchContractEvent for user undefined with:
  Input: {"chainId":"0x89","address":"0xf12F97dc64d59ac7586B0C3dE67f4ef97fEe9349","topic":"TokenMinted(uint256, address)","abi":{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"minter","type":"address"}],"name":"TokenMinted","type":"event"},"limit":500000,"tableName":"TokenMintedEvents","sync_historical":false}
  Result: {"success":false}

you still need to make this work from code now?

The log output from above was with trying to create it from code, so yes - still need to get that working

what is the server url?

Is that the same as Dapp URL?
Dapp URL is: https://1nvxhrqd4tbl.usemoralis.com:2053/server

this was the error:

Error: No provider found for chain 0x89

It looks like that server doesn’t have that specific chain enabled

My bad! It should be 0x13881 for Mumbai.

Apologies - can I ask where you found that error so I can check there next time I run into something similar?

you don’t have access to that error, you couldn’t find it

Got it - thank you for your help, it works now that I have the right chainId.

1 Like