Sync events on local dev chain

Hi,

So yesterday I was working on my local dev chain, it was connected to Moralis as confirmed within the interface and everything was working fine (even the events).
But today Iā€™ve spent 2 hours trying to configure sync events on my local dev chain but it doesnā€™t work now, for no obvious reasonsā€¦
I checked within a hardhat script and I do have events emitted, I configured the right address in the sync contract event. I also recreated new ones, but nothing seems to workā€¦
By the way as of now, it is not possible to directly edit fields within the sync events interface since itā€™s always blocked by the tableName (tableName already in use)ā€¦

{
  "anonymous": false,
  "inputs": [
    {
      "indexed": false,
      "internalType": "address",
      "name": "_auditor",
      "type": "address"
    },
    {
      "indexed": true,
      "internalType": "address",
      "name": "_auditorOwner",
      "type": "address"
    }
  ],
  "name": "auditorRegistered",
  "type": "event"
}
auditorRegistered(address, address)

Hi,
Youā€™ll have to create another event that doesnā€™t use field names that start with that _. Youā€™ll have to change that abi that you paste there so that name fields donā€™t start with _.

Hi,

The problem with ā€œ_ā€ can be fixed by just adding a beforeConsume hooks in cloud functions and replacing ā€œ_auditorā€ by ā€œauditorā€.
Source : Sync and Watch Contract Events plugin : Event data not being registered

Moralis.Cloud.beforeConsume('AuditorRegistered', async (event) => {
  event.auditor = event._auditor.toLowerCase();
});

Everything was working fine so maybe itā€™s something else.

Just to be sure I tried again and changed the contract event parameters names, recreated a sync events (with new abi, address, etcā€¦) and I still get the same problem.

{
  "anonymous": false,
  "inputs": [
    {
      "indexed": false,
      "internalType": "address",
      "name": "auditor",
      "type": "address"
    },
    {
      "indexed": true,
      "internalType": "address",
      "name": "auditorOwner",
      "type": "address"
    }
  ],
  "name": "auditorRegistered",
  "type": "event"
}

now it is preferred to modify the abi instead of using beforeConsume.

Anyway, it should work with the abi that you pasted here, can you also paste your server url?

Yes here it is https://vxriy2xhi2ya.moralishost.com:2053/server

Oh and btw you will see that the table name is now AuditorRegisteredd, as it is not possible to edit without creating a new table :frowning:

Yep, Iā€™m used to add a letter at the end of the table name when I edit an event.

Hey so got any idea? Itā€™s still not working on my side :frowning:

do you still use that Moralis.Cloud.beforeConsume hook? what happens if you remove it in case that you still use it

I just removed it but still nothing happens.

The beforeConsume hook is deprecated ?

I think that the plan is to remove beforeConsume hook

Oh btw here is my debugger script in hardhat to verify the contracts emits events

const hre = require('hardhat');

async function main() {
  const [owner, client] = await hre.ethers.getSigners();

  const AuditorGenerator = await hre.ethers.getContractFactory(
    'AuditorGenerator',
  );
  const auditorGenerator = await AuditorGenerator.attach(
    '0x4A679253410272dd5232B3Ff7cF5dbB88f295319',
  );

  const Factory = await hre.ethers.getContractFactory('Factory');
  const factory = await Factory.attach(
    '0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f',
  );

  await auditorGenerator.createAuditor('Smart Lookup');

  const eventFilter = factory.filters.auditorRegistered(null, owner.address);
  const events = await factory.queryFilter(eventFilter);
  console.log(events.length > 0);
}

main();

The output is

true

So the events are emitted within my local dev chain, the local dev chain is connected to moralis as shown in the dashboard and the contract address, abi, topic are the right ones. I really donā€™t know what else I could do/check.

Here is one of the event I should catch (displayed within the hardhat script

{
    blockNumber: 36,
    blockHash: '0x3c5d6e73f9b40094d79b32eca1890725786494610b6f779ac1cb8604f6ebc411',
    transactionIndex: 0,
    removed: false,
    address: '0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f',
    data: '0x0000000000000000000000002e0331f1e8f1baeba5a28f6c127c6f6ae8ded3d5',
    topics: [
      '0x4160d203139d0099a221d5e8895db40ec758839e48e393b0b2a750914282c72a',
      '0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266'
    ],
    transactionHash: '0x38fab4db335010fc27729770c506e1dda48f97a82e3b7b52ec375b873134bab8',
    logIndex: 0,
    removeListener: [Function (anonymous)],
    getBlock: [Function (anonymous)],
    getTransaction: [Function (anonymous)],
    getTransactionReceipt: [Function (anonymous)],
    event: 'auditorRegistered',
    eventSignature: 'auditorRegistered(address,address)',
    decode: [Function (anonymous)],
    args: [
      '0x2e0331F1e8f1baEBA5A28F6C127c6f6aE8dEd3D5',
      '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
      auditor: '0x2e0331F1e8f1baEBA5A28F6C127c6f6aE8dEd3D5',
      auditorOwner: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
    ]
  }

you could restart the server, try to save again the event with a different table name, but it is not sure that it will solve the problem.
also, some problems could appear if you reuse your Moralis server with different instance of local devchain, like making transactions until block 36 and then resetting back to block 0 the local devchain and starting to make transactions again
also you have to choose historical sync when you sync those events

Already tried to restart the server but i will do it once again to be sure.
I donā€™t understand what you said about ā€œreuse your Moralis server with different instance of local devchainā€, I just start my hardhat dev chain, redeploy my contracts on it and then connect it to moralis thatā€™s all, should I be doing something else ?
And yes I always check sync historical!

Restart didnā€™t solve the problem :weary:

how do you do this part, you reuse a previous blockchain transaction history or you start again from block 0?

No I donā€™t save the state of the local dev chain is that a problem?
How am i supposed to do it?
Can I reset to block 0 on Moralis to fix it ?

Every work session I just restart a new chain, redeploy my contracts, and then link with moralis using frp and after I change the contract addresses in sync event tab.

restart a new chain = a new chain with 0 transactions?

I guess that restarting a new chain on Hardhat starts it frrom block 0 since my contracts are not deployed anymore when I restart.