{"id":19762802,"url":"https://github.com/dutterbutter/webb-squid","last_synced_at":"2025-10-24T23:16:56.541Z","repository":{"id":41137332,"uuid":"508447714","full_name":"dutterbutter/webb-squid","owner":"dutterbutter","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-28T20:40:16.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T23:42:47.109Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dutterbutter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-28T20:40:13.000Z","updated_at":"2022-06-28T20:40:19.000Z","dependencies_parsed_at":"2022-09-08T05:21:44.579Z","dependency_job_id":null,"html_url":"https://github.com/dutterbutter/webb-squid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"subsquid-labs/squid-substrate-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dutterbutter%2Fwebb-squid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dutterbutter%2Fwebb-squid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dutterbutter%2Fwebb-squid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dutterbutter%2Fwebb-squid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dutterbutter","download_url":"https://codeload.github.com/dutterbutter/webb-squid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241094692,"owners_count":19908686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T04:07:04.706Z","updated_at":"2025-10-24T23:16:51.513Z","avatar_url":"https://github.com/dutterbutter.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Squid template project\n\nA starter [Squid](https://subsquid.io) project to demonstrate its structure and conventions.\nIt accumulates [kusama](https://kusama.network) account balances and serves them via GraphQL API.\n\n## Summary\n\n- [Quickstart](#quickly-running-the-sample)\n- [Hosted archives for Parachains](#archives-for-parachains)\n- [Self-hosted archive](#setup-your-own-archive)\n- [Development flow](#dev-flow)\n  - [Database Schema](#1-define-database-schema)\n  - [Entity classes](#2-generate-typeorm-classes)\n  - [DB migrations](#3-generate-database-migration)\n  - [Typegen for Events, Extrinsics and Storage Calls](#4-generate-typescript-definitions-for-substrate-events-and-calls)\n- [Deploy the Squid](#deploy-the-squid)\n- [Conventions](#project-conventions)\n- [Type Bundles](#types-bundle)\n\n## Prerequisites\n\n* node 16.x\n* docker\n\n## Quickly running the sample\n\nExample commands below use [make(1)](https://www.gnu.org/software/make/).\nPlease, have a look at commands in [Makefile](Makefile) if your platform doesn't support it.\nOn Windows we recommend to use [WSL](https://docs.microsoft.com/en-us/windows/wsl/).\n\n```bash\n# 1. Install dependencies\nnpm ci\n\n# 2. Compile typescript files\nmake build\n\n# 3. Start target Postgres database and detach\nmake up\n\n# 4. Start the processor\nmake process\n\n# 5. The command above will block the terminal\n#    being busy with fetching the chain data, \n#    transforming and storing it in the target database.\n#\n#    To start the graphql server open the separate terminal\n#    and run\nmake serve\n```\n\n## Hosted archives for Parachains\n\nSubsquid provides archive data sources for most parachains. \nUse `lookupArchive(\u003cnetwork name\u003e)` to look up the archive endpoint \nby the network name, e.g.\n\n```typescript\nprocessor.setDataSource({\n  archive: lookupArchive(\"kusama\", { release: \"FireSquid\" })\n  //...\n});\n```\n\nTo make sure you're indexing the right chain one can additionally filter by genesis hash:\n\n```typescript\nprocessor.setDataSource({\n  archive: lookupArchive(\"kusama\", { \n    release: \"FireSquid\", \n    genesis: \"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe\" \n  }),\n  //...\n});\n```\n\nIf the chain is not yet supported, \nplease fill out the [form](https://forms.gle/Vhr3exPs4HrF4Zt36) to submit a request.\n\n## Self-hosted archive\n\nTo run archive locally inspect [archive/docker-compose.yml](archive/docker-compose.yml) \nand provide the WebSocket endpoint for your node, then start it with\n\n```bash\ndocker compose -f archive/docker-compose.yml up\n```\n\nTo drop the archive, run\n\n```bash\ndocker compose -f archive/docker-compose.yml down -v\n```\n\nThe archive gateway will be started at port `8888` and it can immediately be used with the processor (even if it's not in sync):\n\n```typescript\nprocessor.setDataSource({\n  archive: `http://localhost:8888/graphql`,\n});\n```\n\nAdditionally, an explorer GraphQL API and a playground will be started at `http://localhost:4350/graphql`. While optional, it's a useful tool for debugging and on-chain data exploration.\n\n## Dev flow\n\n### 1. Define database schema\n\nStart development by defining the schema of the target database via `schema.graphql`.\nSchema definition consists of regular graphql type declarations annotated with custom directives.\nFull description of `schema.graphql` dialect is available [here](https://docs.subsquid.io/schema-spec).\n\n### 2. Generate TypeORM classes\n\nMapping developers use [TypeORM](https://typeorm.io) entities\nto interact with the target database during data processing. All necessary entity classes are\ngenerated by the squid framework from `schema.graphql`. This is done by running `npx squid-typeorm-codegen`\ncommand.\n\n### 3. Generate database migration\n\nAll database changes are applied through migration files located at `db/migrations`.\n`squid-typeorm-migration(1)` tool provides several commands to drive the process.\nIt is all [TypeORM](https://typeorm.io/#/migrations) under the hood.\n\n```bash\n# Connect to database, analyze its state and generate migration to match the target schema.\n# The target schema is derived from entity classes generated earlier.\n# Don't forget to compile your entity classes beforehand!\nnpx squid-typeorm-migration generate\n\n# Create template file for custom database changes\nnpx squid-typeorm-migration create\n\n# Apply database migrations from `db/migrations`\nnpx squid-typeorm-migration apply\n\n# Revert the last performed migration\nnpx squid-typeorm-migration revert         \n```\n\n### 4. Generate TypeScript definitions for substrate events, calls and storage \n\nThis is an optional part, but it is very advisable. \n\nEvent, call and runtime storage data come to mapping handlers as raw untyped json. \nWhile it is possible to work with raw untyped json data, \nit's extremely error-prone and the json structure may change over time due to runtime upgrades.\n\nSquid framework provides tools for generating type-safe wrappers around events, calls and runtime storage items for\neach historical change in the spec version.\n\nTypical usage looks as follows:\n\n```typescript\nfunction getTransferEvent(ctx: EventHandlerContext) {\n    // instantiate the autogenerated type-safe class for Balances.Transfer event\n    const event = new BalancesTransferEvent(ctx);\n    // for each runtime version, reduce the data to a common interface\n    if (event.isV1020) {\n        const [from, to, amount, fee] = event.asV1020;\n        return {from, to, amount};\n    } else if (event.isV1050) {\n        const [from, to, amount] = event.asV1050;\n        return {from, to, amount};\n    } else {\n        return event.asV9130;\n    }\n}\n``` \n\nTo generate type-safe wrappers for events, calls and storage items, use `squid-substrate-typegen(1)`. It expects a\nconfig file of the following structure:\n\n```json5\n{\n  \"outDir\": \"src/types\",\n  // List of chain spec versions.\n  // Can be given as:\n  //    1. Squid archive URL\n  //    2. JSON lines file created by `squid-substrate-metadata-explorer(1)`\n  \"specVersions\": \"https://kusama.archive.subsquid.io/graphql\",\n  \"events\": [ // list of events to generate. To generate all events, set \"events\": true.\n    \"Balances.Transfer\"\n  ],\n  \"calls\": [ // list of calls to generate. To generate all calls, set \"calls\": true.   \n    \"Timestamp.set\"\n  ],\n  \"storage\": [\n    \"System.Account\" // list of storage items. To all storage items, set \"storage\": true\n  ]\n}\n```\n\nIn the [current template](typegen.json), the list of spec versions is\nspecified as an archive URL. However, one can do without archive \nor simply pre-download spec versions via `squid-substrate-metadata-explorer(1)` tool.\n\n```bash\n# Explore the chain (may take some time)\nnpx squid-substrate-metadata-explorer \\\n  --chain wss://kusama-rpc.polkadot.io \\\n  --out kusamaVersions.jsonl\n  \n# Download spec versions from archive\nnpx squid-substrate-metadata-explorer \\\n  --archive https://kusama.archive.subsquid.io/graphql \\\n  --out kusamaVersions.jsonl\n```\n\n## Deploy the Squid\n\nSubsquid offers a free hosted service for deploying your Squid. First, build and run the docker image locally and fix any errors or missing files in Dockerfile:\n\n```sh\nbash scripts/docker-run.sh # optionally specify DB port as an argument\n```\n\nAfter the local run, obtain a deployment key by signing into [Aquarium](https://app.subsquid.io/start) and run \n\n```sh\nnpx sqd auth -k YOUR_DEPLOYMENT_KEY\n```\n\nNext, inspect the Squid CLI help to deploy and manage your squid:\n\n```sh\nnpx sqd squid --help\n```\n\nFor more information, consult the [Deployment Guide](https://docs.subsquid.io/recipes/deploying-a-squid).\n\n## Project conventions\n\nSquid tools assume a certain project layout.\n\n* All compiled js files must reside in `lib` and all TypeScript sources in `src`. \nThe layout of `lib` must reflect `src`.\n* All TypeORM classes must be exported by `src/model/index.ts` (`lib/model` module).\n* Database schema must be defined in `schema.graphql`.\n* Database migrations must reside in `db/migrations` and must be plain js files.\n* `squid-*(1)` executables consult `.env` file for a number of environment variables.\n\n## Types bundle\n\nSubstrate chains that have blocks with metadata versions below 14 don't provide enough \ninformation to decode their data. For those chains, external [type](https://polkadot.js.org/docs/api/start/types.extend) [definitions](https://polkadot.js.org/docs/api/start/types.extend) are required.\n\nSubsquid tools include definitions for many chains, however sometimes external \ndefinitions are still required.\n\nYou can pass them as a special json file (types bundle) of the following structure:\n\n```json5\n{\n  \"types\": {\n    \"AccountId\": \"[u8; 32]\"\n  },\n  \"typesAlias\": {\n    \"assets\": {\n      \"Balance\": \"u64\"\n    }\n  },\n  \"versions\": [\n    {\n      \"minmax\": [0, 1000], // spec version range with inclusive boundaries\n      \"types\": {\n        \"AccountId\": \"[u8; 16]\"\n      },\n      \"typesAlias\": {\n        \"assets\": {\n          \"Balance\": \"u32\"\n        }\n      }\n    }\n  ]\n}\n```\n\n* `.types` - scale type definitions similar to [polkadot.js types](https://polkadot.js.org/docs/api/start/types.extend#extension)\n* `.typesAlias` - similar to [polkadot.js type aliases](https://polkadot.js.org/docs/api/start/types.extend#type-clashes)\n* `.versions` - per-block range overrides/patches for above fields.\n\nAll fields in the type bundle are optional and applied on top of a fixed set of well-known frame types.\n\nNote, that although the structure of subsquid types bundle is very similar to the one from polkadot.js,\nthose two are not fully compatible.\n\n## Differences from polkadot.js\n\nPolkadot.js provides lots of [specialized classes](https://polkadot.js.org/docs/api/start/types.basics) for various types of data. \nEven primitives like `u32` are exposed through special classes.\nIn contrast, the squid framework works only with plain js primitives and objects.\nFor instance, account data is passed to the handler context as a plain byte array.  To convert it into a standard human-readable format one should explicitly use a utility lib `@subsquid/ss58`:\n\n```typescript \n    // ...\n    from: ss58.codec('kusama').encode(rec.from),\n    to: ss58.codec('kusama').encode(rec.to),\n```\n\n\n\n## Graphql server extensions\n\nIt is possible to extend `squid-graphql-server(1)` with custom\n[type-graphql](https://typegraphql.com) resolvers and to add request validation.\nFor more details, consult [Docs](https://docs.subsquid.io/reference/api-extensions)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdutterbutter%2Fwebb-squid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdutterbutter%2Fwebb-squid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdutterbutter%2Fwebb-squid/lists"}