⌘K

Icon SunFilledIcon MoonStars
Generating Types from ABI

Icon LinkGenerating Types from ABI

Icon LinkInstallation

First we install fuels to our project:

pnpm add fuels

Icon LinkHelp

A first glance at the docs:

$ pnpm fuels typegen -h

Usage: fuels typegen [options]

Generate Typescript from Sway ABI JSON files

Options:
  -i, --inputs <path|glob...>  Input paths/globals to your ABI JSON files
  -o, --output <dir>           Directory path for generated files
  -c, --contract               Generate types for Contracts [default]
  -s, --script                 Generate types for Scripts
  -p, --predicate              Generate types for Predicates
  -S, --silent                 Omit output messages
  -h, --help                   Display help

Icon LinkGenerating Types for Contracts

You can generate types for a Sway contract using the command below:

pnpm fuels typegen -i ./abis/*-abi.json -o ./types

The path after the input flag -i should point to the file ending in -abi.json produced when the contract was built.

The path after the output flag -o will be the the output directory for the generated types.

You can omit the --contract option here since it's the default.

Icon LinkGenerating Types for Scripts

To generate types for a Sway script, use the --script flag:

pnpm fuels typegen -i ./abis/*-abi.json -o ./types --script

Icon LinkGenerating Types for Predicates

To generate types for a Sway predicate, use the --predicate flag:

pnpm fuels typegen -i ./abis/*-abi.json -o ./types --predicate

See also: