Repopulating Automatic Tables after Deletion

i’m a bit confused now with the new web3 api:
I’ve built my app using the NTFOwners tables that are populated by moralis, but it’s unreliable now. I’ve deleted all NFTOwners entries, but they are not anymore auto populated by a sync job. Lots of them missing. The trouble started when I tried to make database access secure and started to lock down Public access. Many sync jobs don’t do their work when access is not set to Public, as I’ve referenced in:

Is it better practice now to use the web3 api to pull data in the front end? If so, isn’t that slower and maybe more expensive than caching it in my db?

Can you include subdomain and example of NFT owner address that is not reflected correctly in the DB?

gago4ywcuqck.usemoralis.com

https://deep-index.moralis.io/api/v2/nft/0x2c8ebc1a84db37104c7821f39d26a167644eab56/owners?chain=rinkeby&format=decimal

Basically I removed all Public access, since it’s all set to Read/Write by default which is not what we want most of the time.
I’ve outlined some of the problems in the other forum thread, but I think not all of them are solved.
Since I don’t know the code you use to sync those tables, I don’t know what’s causing this behaviour.

I deleted those records on purpose by the way. I want to make sure when I have to recover data from chain it all works. Your internal sync jobs are a black hole for me, so I’m thinking about doing it all myself now via the web3 API …

EthNFTOwners shows which NFTs your Useraddresses have, not all owners of an NFT so you can’t compare it to the API (API shows all owners even thouse that are not using your app).

To help - we need an example of a user address that is in your User table that has wrong data about it’s NFT Ownership in ´EthNFTOwners`.

address 0xfac18d92fa347b6d733300df893ab3db6d09301d has many when calling the mentioned web3 api, but just 2 populated in NFTOwners
The real serious issue is CLP in my opinion.

ok thanks we will check

thanks!
Another thing I’d like to review:
NFTOwners createdAt cannot be used to know when the item was minted, as this is the time when the item was synced.
There’s block_number but I’m wondering what you use here, because in the web3 api /nft/{address}/owners we have:

"block_number": "9201767",
"block_number_minted": "9136207",

and in NFTOwners we see 9201767 which I’m guessing is the Confirmed block?

In web3 api /nft/{address} there’s no block_numbers at all.

I was using createdAt to check if an item was ‘new’, or X days old. Now I know I need to use block_number and figure out the date myself, comparing it to current block… not very handy.
What is your opinion?

after an hour: nothing populated in the NFTOwners db, no errors is log.
What is supposed to trigger a sync?

If you manually deleted entries from auto-sync tables and want them back use this function and specify the address you want to recover

https://docs.moralis.io/moralis-server/automatic-transaction-sync/historical-transactions#watch-address-from-code

wow a lot of nice new documentation I see, didn’t keep up too busy buidling haha.

So basically I would make a cloud function to iterate all users wallet address and call the function.
Did that and works, all data back. Very happy to know how that works now behind the hood so I have control over my data!

// repair NFTOwners data
Moralis.Cloud.job('repopulateNFTOwners', async (request) =>  {
  const userQuery = new Moralis.Query(Moralis.User)
  const users = await userQuery.find({useMasterKey:true})
  for (let i = 0; i < users.length; i++) {
    await Moralis.Cloud.run(`watch${request.params.input.network}Address`, {address: users[i].attributes.ethAddress})
  }
})

2 Likes

Okok great to hear, checking the permissions issue in the separate thread :thread:

1 Like