The implemantation friendteh subgraph) with Squid SDK docs for a complete reference.
Dependencies: Node.js v16 or newer, Git, Docker.
# 0. Install @subsquid/cli a.k.a. the sqd command globally
npm i -g @subsquid/cli
# 1. clone repository
sqd clone https://github.com/nashirudin/friendtech-migration
# 2. Go to folder
cd friendtech-migration
# 3. Rename .env.example to .env
# 4. Install dependencies
npm ci
# 5. Start a Postgres database container and detach
sqd up
# 6. Build the squid
sqd build
# 7. Start both the squid processor and the GraphQL server
sqd run .
A GraphiQL playground will be available at localhost:4350/graphql.
You can also start squid services one by one:
sqd process
sqd serve
Start development by defining the schema of the target database via schema.graphql
.
Schema definition consists of regular graphql type declarations annotated with custom directives.
Full description of schema.graphql
dialect is available here.
Mapping developers use TypeORM EntityManager
to interact with target database during data processing. All necessary entity classes are
generated by the squid framework from schema.graphql
. This is done by running sqd codegen
command.
All database changes are applied through migration files located at db/migrations
.
squid-typeorm-migration(1)
tool provides several commands to drive the process.
## drop create the database
sqd down
sqd up
## replace any old schemas with a new one made from the entities
sqd migration:generate
See docs on database migrations for more details.
It is necessary to import the respective ABI definition to decode EVM logs. One way to generate a type-safe facade class to decode EVM logs is by placing the relevant JSON ABIs to ./abi
, then using squid-evm-typegen(1)
via an sqd
script:
sqd typegen
See more details on the squid-evm-typegen
doc 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. sqd(1)
andsquid-*(1)
executables consult.env
file for environment variables.