Missing the Historical Sync API for self hosted

Hi,

I have setup the server for parse-server-migration that uses the raw parse implemenation with some Moralis SDK streams API added on top of that.

My pipeline is bult with the legacy database classes that are created from the historical event synch.

I now want to synchronize historical events on a server that runs locally. How can I store the historical events in the same way as the old moralis SDK used to do it?
I only found that I can now access the getContractEvents and then process it by myself into parse objects or does there exist some function equivalent to what happens with the Moralis hosted version? https://docs.moralis.io/web3-data-api/evm/how-to-get-the-events-for-a-contract

Did I miss some documentation?

Thanks in advance and absolutely astonishing documentation + services so far!

Hi,

There are 2 options now, you can use web3api to get the historical events and insert them in the database, or, if you still have a server you can do a historical sync on the server and then export that data and import it in your self hosted server.

We don’t have yet historical data for streams API.

1 Like

Thanks for the quick advice!

I decided to try the manual population of my local database with the use of the getContractEvents()

Unfortunately, I’m stuck at the step of how to process the returned EvmEvent.

It has datafields with {from, to, value} but I don’t know where I can access the event data. It is a custom contract event that I plan to decode with the use of the ethers.utils.Interface.

Edit:
I just noticed that the log API endpoint has this data entry. Should I use this instead?

It doesn’t seem like I can filter for the topic there. The topic0-4 seem to be positional filters and I would like to have only a specific event in whatever position.

Another Edit:
I just noticed that I get the same amount of events with the topic0 filter. So it seems to work as a if any topic is topic0 or topic1 or topic2. (Maybe worth another user story in the back log to clarify this documentation)
I would have expected to find the custom event fields in the returned EvmEvent object. It seems that it was a problem of Typescript autosuggestion it to be a EvmEvent and it filled out the data with {from, to, value}. I now used JSON.stringify to investigate it and it turns out that it has the correct fields from the ABI that is sent with the body of the HTTP request to your API.

Thanks again for all your help regarding the local server instance, it looks like it’ll be working out as you suggested!

If you havn’t already considered, you could offer a typescript generic that accepts a typechain EventObject. That’ll be a charming developer experience and great for production quality if you support typechain. It looks pretty stable to me.

How many compute units are used by the getContractEvents? I didn’t see it in the Web3Api endpointWeights

{
“endpoint”: “getContractEvents”,
“path”: “/{address}/events”,
“price”: 2,
“rateLimitCost”: 2
},

1 Like

Must have experienced temporary blindness, thanks!

1 Like

I just got up to speed with the ongoing disable_total as string bug and it seems that it is the same with the fromBlock and toBlock for the getContractLogs.

Related to the small chaos in breaking changes, could it be that something with the return parameters changed? I passed the same custom abi to getContractEvents and now it returns undefined in the data field again.
Yesterday I received the custom params / inputs / args.

I now had to resort to the getContractLogs and then use ethers.utils.Interface(abi).parseLog({topics: event.topics, data: event.data}) to decode the parameters.

can you give an exact example that doesn’t work as expected?

If I query a contract event with

getContractEvent({... abi: eventAbi})

and then process the result EvmEvent, then typescript shows undefined for data: {from, to, value}.
This makes sense since the event does not have these parameters.

But now when I use JSON.stringify(response.result.shift()) then I also do not see the custom event parameters.

I now had to use getContractLogs filter by topic0 to get only the desired event log. Then use for example ethers.utils.Interface(abi).decodeLog(ethers.utils.Interface(abi).getEvent(eventName), response.result[0].topics, response.result[0].data

That way I have now populated the local parse database in the same way as the Legacy moralis-hosted synch worked.

It was just a bit more cumbersome since I had to decode the logs manually and use the topic0 filter. The getContractEvent was a very neat (kiss, dry) way for the code base.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.