The fuels
CLI consists of a couple of commands.
npx fuels@{{fuels}} help init
Options:
--path <path> Path to project root (default: current directory)
-w, --workspace <path> Relative dir path to Forc workspace
-c, --contracts [paths...] Relative paths to Contracts
-s, --scripts [paths...] Relative paths to Scripts
-p, --predicates [paths...] Relative paths to Predicates
-o, --output <path> Relative dir path for Typescript generation output
--forc-path <path> Path to the `forc` binary
--fuel-core-path <path> Path to the `fuel-core` binary
--auto-start-fuel-core Auto-starts a `fuel-core` node during `dev` command
--fuel-core-port <port> Port to use when starting a local `fuel-core` node for dev mode
-h, --help Display help
Creating a sample fuel.config.ts
file:
npx fuels@{{fuels}} init --contracts ./my-contracts/* --output ./src/sway-contracts-api
Using Forc workspaces? Try this instead:
npx fuels@{{fuels}} init --workspace ./sway-programs --output ./src/sway-programs-api
This will give you a minimal configuration:
<<< @/../../demo-fuels/fuels.config.minimal.ts#config{ts:line-numbers}
In a nutshell:
.
├── sway-programs # <— forc workspace
├── src
│ └── sway-programs-api # <— output
├── fuels.config.ts
└── package.json
npx fuels@{{fuels}} help build
Options:
--path <path> Path to project root (default: "/Users/anderson/Code/fuel/fuels-ts/apps/docs")
-d, --deploy Deploy contracts after build (auto-starts a `fuel-core` node if needed)
-h, --help Display help
Examples:
npx fuels@{{fuels}} build
- Build all Sway programs under your
workspace
usingforc
1 - Generate types for them using
fuels-typegen
2
npx fuels@{{fuels}} build --deploy
Using the --deploy
flag will additionally:
- Auto-start a short-lived
fuel-core
node if needed (docs) - Run
deploy
on that node
This is useful when working with contracts because a contract's ID is generated only on deployment.
npx fuels@{{fuels}} deploy
The fuels deploy
command does two things:
- Deploy all Sway contracts under
workspace
. - Saves their deployed IDs to:
./src/sway-programs-api/contract-ids.json
{
"myContract1": "0x..",
"myContract2": "0x.."
}
Use it when instantiating your contracts:
<<< @/../../demo-fuels/src/index.test.ts#using-generated-files{ts:line-numbers}
For a complete example, see:
Automatic deployment of proxy contracts can be enabled in Forc.toml
.
For more info, please check these docs:
- Proxy Contracts
- Sway Libs / Upgradability Library
- Sway Standards / SRC-14 - Simple Upgradable Proxies
npx fuels@{{fuels}} dev
The fuels dev
command does three things:
- Auto-start a short-lived
fuel-core
node (docs) - Runs
build
anddeploy
once at the start - Watches your Forc workspace and repeats the previous step on every change
In
dev
mode, every time you update a contract on your Forcworkspace
, we re-generate type definitions and factory classes for it, following your pre-configuredoutput
directory. If it's part of another build system running in dev mode (i.e.next dev
), you can expect it to re-build / auto-reload as well.
npx fuels@{{fuels}} node
Starts a short-lived fuel-core
node and requires a fuels.config.ts
config file.
Generate one with fuels init
:
<<< @/../../demo-fuels/fuels.config.minimal.ts#config{ts:line-numbers}
Manually generates type definitions and factory classes from ABI JSON files.
npx fuels@{{fuels}} help typegen
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
For more info, check:
Check for version incompatibilities between your Fuel Toolchain component versions, matching them against the ones supported by the Typescript SDK version that you have.
npx fuels@{{fuels}} versions
┌───────────┬───────────┬────────────────┬─────────────┐
│ │ Supported │ Yours / System │ System Path │
├───────────┼───────────┼────────────────┼─────────────┤
│ Forc │ {{forc}} │ {{forc}} │ forc │
├───────────┼───────────┼────────────────┼─────────────┤
│ Fuel-Core │ {{fuelCore}} │ {{fuelCore}} │ fuel-core │
└───────────┴───────────┴────────────────┴─────────────┘
You have all the right versions! ⚡