A typegen is a tool for generating utility code for technology-specific operations such as decoding.
Solana typegen:
- decodes instruction and log message data based on the IDL
- exposes useful constants such as program IDs and instruction discriminators
- provides functions that simplify selecting data items based on accounts
Install it with
Replace npx squid-solana-typegen with npx @subsquid/solana-typegen if you don’t want to install the package.
The squid-solana-typegen tool generates TypeScript facades for Solana instructions and logs. It takes JSON IDLs as inputs. The IDLs can be specified in three ways:
-
as a plain JSON file(s):
If you use this option, you can also place your JSON IDLs to the
idl folder and run
-
load IDL from a Solana node or the SolanaFM registry and generate types:
Use
--solana-rpc-endpoint <url> to choose the RPC endpoint for onchain IDL
lookup.
-
load an IDL from an HTTP(S) URL:
Pass --clean to delete the output directory before generation.
Usage
The generated utility modules have three intended uses:
-
Constants: Solana instruction discriminators:
-
Decoding of Solana instructions
-
Simplifying the account-specific data requests
The generated instruction descriptors also work with getInstructionData()
and getInstructionDescriptor() from @subsquid/solana-stream.