Proper Method To Query & Add More On-Chain Data To Table?

This is more of a top-level question that Iā€™ve been trying to solve. Keep in mind I am not a developer but have some experience with front-end.

I have a Moralis server set up to watch a locking contract for dxsale. The data is captured beautifully in the tables.

However I want to grab more data to add into new columns in the table. For instance, grabbing the token address of whatā€™s being locked. This involves some queries of the initial data Moralis is grabbing. Another example is that I have an API I can query to get more information on that token, which I would then also like to add to that table.

Iā€™m not sure how to approach thinking about how to get and add this data to my tables. Iā€™ve checked all the examples and still Iā€™m not sure how I would execute server side code to get this additional info. I have two thought processesā€¦

  1. Execute cloud functions when users login to fill in the data, and have a state variable that indicates whether a row has already been filled (by another user interaction). In a sense, piggybacking on user interaction to collect that additional information. This is not quite what I want, since if no users log in for a period of time, the data in the table may not be updated as quickly as Iā€™d want to.

  2. Set up another server to talk to the Moralis server through Webhooks? Iā€™m really lost here. Maybe schedule repeating cronjobs, but I donā€™t see much ability to add custom jobs. I guess Iā€™m looking for a way to run serverside functions independently from users.

Any advice on how to approach this is most appreciated!

Hi Mark,

What youā€™re looking for is a beforeSave trigger on your event table. This will fire whenever new data is inserted into the table. See the Trigger docs here:

https://docs.moralis.io/triggers#beforesave

You can make API calls from Triggers and Cloud Function via HttpRequest:
https://docs.moralis.io/httprequest

If you need ERC20 token metadata like name, symbol, decimals you can use the Deep Index API endpoint /token/ERC20/metadata the NFT endpoint is /nft/metadata. You can find the Swagger docs for these endpoints on the Deep Index API page on your Moralis Admin page. See the getting started docs for the Deep Index API.

https://docs.moralis.io/deep-index-rest-api/deep-index-api

Hope that helps!

Amazing, thank you. This helps a lot!

Will the beforeSave trigger work on the ā€œSync and Watch Addressā€ plugin?

If Iā€™m understanding this correctly, the cloud code will run before each new entry of designated table and thatā€™s how I will append all extra data I need?

Hey @markyjennings

Take a look at Sync and Watch Address Topic.

ā€œSync and Watch Addressā€ Plugin is a cloud function and the same rules apply to it

Yes, you are right. beforeSave helps you to handle the info after it was changed and before it was added to the table.