--- description: >- A tool for generating type-safe TypeScript classes for runtime events and extrinsic calls --- # Hydra Typegen ## Motivation Hydra Typegen is a code generation tool for creating Typescript types for substrate events and extrinsics. Its primary use-case is to provide type-safe interfaces for Hydra mappings. For example, once a typescript class for the `Balances.Transfer` event is generated, a mapping can look like ```typescript export async function balancesTransfer({ event }: EventContext & StoreContext ) { const [from, to, value] = new Balances.TransferEvent(event).params const { dest, value } = new Balances.TransferCall(event).args ... } ``` ## Quickstart A minimal example for generating classes for the `Balances.Transfer` and `Treasury.Deposit` events in Kusama: ```bash hydra-typegen typegen --metadata wss://kusama-rpc.polkadot.io Balances.Transfer ``` It is also possible to run `hydra-typegen` against a YAML config file ```bash hydra-typegen typegen typegen.yml --debug ``` ## Typegen config Typegen config file has the following structure:
| Field | Type | Description |
|---|---|---|
metadata.source
|
string | Where typegen will source node metadata. Can either be a ws endpoint or
a path to a static json file with the same content as the result of state_getMetadata RPC
call |
metadata.blockHash
|
string | (optional) If metadata.source is a WS endpoint, hash of the
block from which metadata will be sourced, in hex format |
events
|
[string] | A list of events for which TS classes will be generated, in the format <section>.<name>
|
calls
|
[string] | A list of extrinsics (calls) for which TS classes will be generated, in
the format <section>.<method>
|
outDir
|
string | Root directory for the generated classes |
strict
|
boolean |
Default: If true, the event/extrinsic constructor throws an error if the raw data does not match the format in metadata (e.g. due to a runtime upgrade). |
customTypes.lib
|
string | (optional) Import path for custom types that will be used in the generated sources |
customTypes.typedefs
|
string | (optional) Path to a JSON file with custom type definitions, as expected
by polkadot.js createApi method |