Icon SunFilledIcon MoonStars

Icon LinkGenerating Types from ABI

Icon LinkInstallation

First we install fuels to our project:

yarn add fuels

Icon LinkHelp

A first glance at the docs:

$ yarn exec fuels typegen -h

Usage: fuels typegen [options]

generate typescript from contract 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 code for contracts [default]
  -s, --script                 generate code for scripts
  --silent                     omit output messages
  -h, --help                   display help for command

Icon LinkGenerating Types for Contracts

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

yarn exec 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:

yarn exec 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:

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

See also:

Was this page helpful?