Programatically add contract event sync not working

Hello!

I am trying to programatically add syncs for SC events to log on the database and notify my GCP service for it to make some updates in other service. I followed this doc. I am trying to add the sync to the SC events with the following code:

let options = {
    chainId,
    address,
    topic,
    abi,
    limit: 50,
    tableName: 'Transfer',
    sync_historical: false,
  };

  const hookResult = await Moralis.Cloud.run('watchContractEvent', options, {
    useMasterKey: true,
  });

The specific values that I am passing as options are the following.

{
  options: {
    chainId: '0x1',
    address: '0x6b175474e89094c44da98b954eedeac495271d0f',
    topic: 'Transfer(address,address,uint256)',
    abi: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object]
    ],
    limit: 50,
    tableName: 'TransferBatchOne',
    sync_historical: false
  },
  hookResult: { success: false }
}

As you can see, I am getting an unsuccessful response. I have tried watching on other chains and it only says it works for rinkeby (chainId: 0x4). But even on rinkeby, I see no table created on the database or events logged there after the tokens are moved. Am I missing something?

can you paste that specific abi that you use there? it should be readable

{
  "options": {
    "chainId": "0x1",
    "address": "0x6b175474e89094c44da98b954eedeac495271d0f",
    "topic": "Transfer(address,address,uint256)",
    "abi": [
      {
        "constant": true,
        "inputs": [],
        "name": "name",
        "outputs": [
          {
            "name": "",
            "type": "string"
          }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
      },
      {
        "constant": false,
        "inputs": [
          {
            "name": "_spender",
            "type": "address"
          },
          {
            "name": "_value",
            "type": "uint256"
          }
        ],
        "name": "approve",
        "outputs": [
          {
            "name": "",
            "type": "bool"
          }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
      },
      {
        "constant": true,
        "inputs": [],
        "name": "totalSupply",
        "outputs": [
          {
            "name": "",
            "type": "uint256"
          }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
      },
      {
        "constant": false,
        "inputs": [
          {
            "name": "_from",
            "type": "address"
          },
          {
            "name": "_to",
            "type": "address"
          },
          {
            "name": "_value",
            "type": "uint256"
          }
        ],
        "name": "transferFrom",
        "outputs": [
          {
            "name": "",
            "type": "bool"
          }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
      },
      {
        "constant": true,
        "inputs": [],
        "name": "decimals",
        "outputs": [
          {
            "name": "",
            "type": "uint8"
          }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
      },
      {
        "constant": true,
        "inputs": [
          {
            "name": "_owner",
            "type": "address"
          }
        ],
        "name": "balanceOf",
        "outputs": [
          {
            "name": "balance",
            "type": "uint256"
          }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
      },
      {
        "constant": true,
        "inputs": [],
        "name": "symbol",
        "outputs": [
          {
            "name": "",
            "type": "string"
          }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
      },
      {
        "constant": false,
        "inputs": [
          {
            "name": "_to",
            "type": "address"
          },
          {
            "name": "_value",
            "type": "uint256"
          }
        ],
        "name": "transfer",
        "outputs": [
          {
            "name": "",
            "type": "bool"
          }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
      },
      {
        "constant": true,
        "inputs": [
          {
            "name": "_owner",
            "type": "address"
          },
          {
            "name": "_spender",
            "type": "address"
          }
        ],
        "name": "allowance",
        "outputs": [
          {
            "name": "",
            "type": "uint256"
          }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
      },
      {
        "payable": true,
        "stateMutability": "payable",
        "type": "fallback"
      },
      {
        "anonymous": false,
        "inputs": [
          {
            "indexed": true,
            "name": "owner",
            "type": "address"
          },
          {
            "indexed": true,
            "name": "spender",
            "type": "address"
          },
          {
            "indexed": false,
            "name": "value",
            "type": "uint256"
          }
        ],
        "name": "Approval",
        "type": "event"
      },
      {
        "anonymous": false,
        "inputs": [
          {
            "indexed": true,
            "name": "from",
            "type": "address"
          },
          {
            "indexed": true,
            "name": "to",
            "type": "address"
          },
          {
            "indexed": false,
            "name": "value",
            "type": "uint256"
          }
        ],
        "name": "Transfer",
        "type": "event"
      }
    ],
    "limit": 50,
    "tableName": "TransferBatchOne",
    "sync_historical": false
  },
  "hookResult": {
    "success": false
  }
}

It is not going to work with that _ there, you have to remove it in the abi.
You need only the abi specific to that function, not the entire abi of the contract.

1 Like

Now it could be other issue. Can you also paste the server url?

1 Like

https://g3ldtkrxvxui.usemoralis.com:2053/server

Which is bugging me is that if I use chainId 0x4 (rinkeby) it returns true, but it does not create anything in the DB either:

Started https://k3n8eaxwz2sm.usemoralis.com:2053/server
{
  "options": {
    "chainId": "0x4",
    "address": "0xb49dbe8e2a5a140b3b810c33ac2ba4907a3ca95e",
    "topic": "Transfer(address,address,uint256)",
    "abi": {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "name": "from",
          "type": "address"
        },
        {
          "indexed": true,
          "name": "to",
          "type": "address"
        },
        {
          "indexed": false,
          "name": "value",
          "type": "uint256"
        }
      ],
      "name": "Transfer",
      "type": "event"
    },
    "limit": 50,
    "tableName": "TransferBatchOne",
    "sync_historical": false
  },
  "hookResult": {
    "success": true
  }
}

on what chain id you want to sync that event? the server is on mainnet

1 Like

it looks like you made it work meanwhile

1 Like

Just realised that I was messing the servers and chainIds. Now it is workiing properly. Thanks Cryptokid!

1 Like