First we install fuels
to our project:
pnpm add fuels@0.97.0
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
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 output directory for the generated types.
You can omit the --contract
option here since it's the default.
To generate types for a Sway script, use the --script
flag:
pnpm fuels typegen -i ./abis/*-abi.json -o ./types --script
To generate types for a Sway predicate, use the --predicate
flag:
pnpm fuels typegen -i ./abis/*-abi.json -o ./types --predicate
See also: