Multichain indexing
Squids can extract data from multiple chains into a shared data sink. If the data is stored to Postgres it can then be served as a unified multichain GraphQL API. To do this, run one processor per source network:-
Make a separate entry point (
main.tsor equivalent) for each processor. The resulting folder structure may look like this:srcbscmain.tsprocessor.tsethmain.tsprocessor.ts
- Arrange for running the processors alongside each other conveniently:
- Add
sqdcommands for running each processor tocommands.json, e.g.Full examplecommands.json - If you are going to use
sqd runfor local runs or deploy your squid to SQD Cloud, list your processors at thedeploy.processorsection of your deployment manifest:Make sure to give each processor a unique name!
- Add
On Postgres
Also ensure that- State schema name for each processor is unique
src/bsc/main.ts
src/eth/main.ts
- Schema and GraphQL API are shared among the processors.
For full isolation instead, give each processor its own
DB_SCHEMA — one Postgres schema per chain. The processors’ tables never overlap, which removes cross-chain write concurrency entirely, and each chain can also keep its state in the same schema (set stateSchema to the same value). The cost is on the serving side: an OpenReader instance reads a single DB_SCHEMA, so you expose one GraphQL API per chain (or add a stitching/gateway layer) rather than the unified API above. Choose shared schemas for a unified API, isolated schemas to avoid separating the data per-chain manually.Handling concurrency
-
Cross-chain data dependencies are to be avoided. With the default isolation level used by
TypeormDatabase,SERIALIZABLE, one of the processors will crash with an error whenever two cross-dependent transactions are submitted to the database simultaneously. It will write the correct data when restarted, but such restarts can impact performance, especially in squids that use many (>5) processors. -
The alternative isolation level is
READ COMMITTED. At this level data dependencies will not cause the processors to crash, but the execution is not guaranteed to be deterministic unless the sets of records that different processors read/write do not overlap. - To avoid cross-chain data dependencies, use per-chain records for volatile data. E.g. if you track account balances across multiple chains you can avoid overlaps by storing the balance for each chain in a different table row. When you need to combine the records (e.g. get a total of all balaces across chains) use a custom resolver to do it on the GraphQL server side.
-
It is OK to use cross-chain entities to simplify aggregation. Just don’t store any data in them: