Moralis - 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.

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…

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.

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!

Answers 1

  • 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 Moralis 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!


Related Questions