Skip to main content
Version: Firesquid

Squid Substrate typegen


The Squid substrate typegen tool is part of Subsquid SDK and is used for generating TypeScript interface classes for Substrate events and calls.

Options for squid-substrate-typegen command

-h or --helpdisplay help for command
configJSON file with optionsyes


npx squid-substrate-typegen typegen.json

The typegen.json config file has the following structure. The specVersions fields is either

"outDir": "src/types",
"specVersions": "kusamaVersions.jsonl",
// see types bundle section below
"events": [
// list of events to generate
"calls": [
// list of calls to generate
"storage": [
// Qualified storage item name: "${Prefix}.${item}"
"constants": [
// Qualified name for the constants to be generated: "${Prefix}.${item}"

To generate all items defined by the runtime, set any of events, calls, storage or constants to true, e.g.

"outDir": "src/types",
"specVersions": "kusamaVersions.jsonl",
// generate facade classes for all runtime constants
"constants": true

TypeScript class wrappers

The result of the typegen command can be found in the specified outDir (src/types by default). The wrapper classes for event, calls, storage and constants are generated in events.ts, calls.ts, storage.ts and constants.ts respectively.


Below are sample code snippets showcasing how the classes generated by typegen are used in the mappings.

Events and Calls

import {BalancesTransferEvent} from "./types/events"
import {BalancesForceTransferCall} from "./types/calls"
// ... TypeormDatabase(), async ctx => {
for (let block of ctx.blocks) {
for (let item of block.items) {
if (item.kind == "event" && == "Balances.Transfer") {
// decode the event `Balances.force_transfer`
let e = new BalancesTransferEvent(ctx, item.event)
if (e.isV1020) {
let [from, to, amount,] = e.asV1020
// ... decode all runtime versions similarly with e.isVXXX/e.asVXXX
if (item.kind == "call" && == "Balances.force_transfer") {
// decode the call `Balances.force_transfer`
let c = new BalancesForceTransferCall(ctx,
if (c.isV1020) {
let {source, dest, value} = c.asV1020
// ... decode all runtime versions similarly with c.isVXXX/c.asVXXX


See Storage queries


import {SystemMaximumBlockLengthConstant} from "./types/constants"
// ... TypeormDatabase(), async ctx => {
// read System.MaximumBlockLength length
let c = new SystemMaximumBlockLengthConstant(ctx)`System.MaximumBlockLength (runtime version V1): ${c.asV1()}`)