Unable to save multiple contract addresses/events to a single table

We want to watch the ERC-721 transfer function but only for our select contract addresses that are using the function. We are able to watch a single address and add it to a table, and we are able to watch all addresses by programmatically entering an empty string following this documentation.

https://docs.moralis.io/moralis-server/automatic-transaction-sync/smart-contract-events#watching-from-code

However, we are unable to programmatically add a new address to that same table.
(.ie when creating a new collection contract that supports ERC-721 transfer)

How can we achieve this?

If we were to create a new table for every contract that we want to watch, how can we consolidate all of those new tables into a single table? From my understanding of Moralis functionality we would have to have an afterSave event for each table, however we would need to create those afterSave cloud functions dynamically as well so this is not feasible.

You could create a job that runs every minute to consolidate those tables.

will having a job that consolidates 1000s of tables together every minute be an effective solution in terms of performance? Is there a way to just watch multiple contract events from multiple contract addresses and send them all to a single table?

You could use beforeSave and afterSave hooks to save in a different table.

the nature of the problem involves dynamically creating tables, thus we would have to dynamically create the beforeSave/afterSave hooks while keeping track of the names of the newly created tables in a new table. We will attempt a similar solution as dynamically creating cloud functions does not seem feasible, but it seems like the solution is more complicated than should be necessary for a usecase like this.

any update on this ? i need to watch event from same smart contract but different address

you can not use same table as of now, you will have to use separate tables

i probably had 10-20 address , i dont want to see my moralis dashboard with 20 table with simmiliar name T_T

I don’t see a problem in having 20 tables in dashboard

i want to try that but i got this " tableName should contain only letters"
i want to my table name will look like this and i can create job to loop all table
EventNameContract1
EventNameContract2

You could try:

EventNameContractA
EventNameContractB
EventNameContractC
EventNameContractD

This is actually what I’m currently doing (the separate tables part, not the merging yet). It actually works reasonably well, but it feels like it may get out of hand once 100,200…1000 tokens are added/tracked.

Do we have a better way (yet) of merging tables? Also, what is the best way to “dynamically” list all existing tables so as to iterate through them in the script and merge (basically a table names query)?

NOTE: Currently in test. Having to slog through multiple (dynamically created) tables to make sure all rows are empty, just to delete them is quite taxing. :crazy_face: Also, the “only letters” limitation is a bit rough. I’ve currently chosen to base58 the original address hash, shorten it sliiiiiiiightly, then append the token chain text. No collisions so far! :dizzy_face:‍:dizzy:

there is the option now to sync all the evens in the same table by adding the event sync from code, and by not providing the contract address, you have to use a syntax like this:

Moralis.Cloud.run(“coreservices_addEventSync”, options, { useMasterKey: true });

Excellent. Would you mind giving a more explicit example of adding sync events without a contract address? I’m a bit lost as to what that means.

Would it sync every event from every supported DEX or what?

Check the example from documentation where an event sync is added from code.

Alright, so it appears it could/would be filtered by chain.

Any quality way (Moralis or otherwise) to correlate the event to the specific DEX (especially when the event signature and chain is the same) and CHAIN (in the rare cases where the token address is the same across all chains)?

If the contract address is the same on multiple chains, you can not sync in the same table now as you will need to specify the contract address and the chain. In that case you will have to use multiple tables.
In few months we will work on developing an API for syncing data directly into your backend.

Fair enough. I can create a separate “sync” per chain (rather than my current method of separate syncs per individual contract :scream:). Not tooooo many moving parts.

Is there a function in Moralis code (advanced or otherwise) to list existing syncs/tables, etc? For example, for the purpose of running local “init” functions to ensure tables are present or create them if necessary . . . or for deleting as needed.

You can make a query in the database to see what entries are already present in a table specific to event syncs. You can also try to add them and if the table is already used then it will return a specific error message.

Hrm, I’m thinking more of:

“I have NO IDEA what tables were left from the previous dev session. I’d like to go through and remove any with the ‘dev’ prefix”

Is there no way to query exactly what’s there rather then pinging for errors? Something like Moralis.listTables()?