This project purpose is to aggregate events from the Substrate-based blockchain and provide GraphQL API enpoint for accessing on chain historic data, events and calls. Project uses Subsquid squid technology, for more information see Subsquid documentation.
- node 16.x
- docker
- npm
- access to the blockchain node
- Run the processor
- Run docker container via docker compose
- Build the squid, for more information follow this documentation
- from the processor dir run:
npm i -g @subsquid/cli@latest
- check version:
sqd --version
- initialize squid with :
sqd init <project-name> --template substrate
- install dependencies:
npm i
- from the processor dir run:
- Launch Postgres in a detached Docker container:
sqd up
- Generate
model
files,v1
andevents
: Workflow section, parts 1 and 3. - Build the project and start the processor:
sqd process
- On another instance of the terminal run GraphQL server:
sqd serve
- GraphQL API will be accessible under
/graphql
endpoint on the port prompted bysqd serve
- Entities are generated based on the
schema.graphql
file, instruction on defining entities may be found under this Subsquid documentation page. To map changes fromschema.graphql
to the codebase (files inside/model/generated
) callsqd codegen
method, delta between current state of database and state of the model is represented by the migration file - new one must be generated after each change made to the model (usingsqd migration:generate
command). - All squid command's with brief explanation are defined in the
commands.json
file - In
/types
directory there are generated classes that represent access API for the Substate chain metadata: to update those files after chain node change call generate.jsonl
file by running:squid-substrate-metadata-explorer --chain <url> --out <file>
where in<url>
write chain node url and in<file>
output destination and name of your.jsonl
file (by relation to the root project directory). Next callsqd typegen <file>
. - CRUD operations on the database are made using
BatchContext.store
TypeormDatabase
member. General info about usingTypeormDatabase
is available here. For advanced query operations see this documentation page.
Squid tools assume a certain project layout.
- All compiled js files must reside in
lib
and all TypeScript sources insrc
. The layout oflib
must reflectsrc
. - All TypeORM classes must be exported by
src/model/index.ts
(lib/model
module). - Database schema must be defined in
schema.graphql
. - Database migrations must reside in
db/migrations
and must be plain js files. squid-*(1)
executables consult.env
file for a number of environment variables.
See the full description in the documentation.