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:

You can make API calls from Triggers and Cloud Function via 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.

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.