Back to Fuels Ts

Commands

apps/docs/src/guide/fuels-cli/commands.md

0.103.06.4 KB
Original Source
<script setup> import { data } from '../../versions.data' const { fuels, forc, fuelCore } = data </script>

Commands

The fuels CLI consists of a couple of commands.

fuels init

console-vue
npx fuels@{{fuels}} help init
console
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:

console-vue
npx fuels@{{fuels}} init --contracts ./my-contracts/* --output ./src/sway-contracts-api

Using Forc workspaces? Try this instead:

console-vue
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:

sh
.
├── sway-programs # <— forc workspace
├── src
│   └── sway-programs-api # <— output
├── fuels.config.ts
└── package.json

See more

fuels build

console-vue
npx fuels@{{fuels}} help build
console
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:

console-vue
npx fuels@{{fuels}} build
  1. Build all Sway programs under your workspace using forc <sup>1</sup>
  2. Generate types for them using fuels-typegen <sup>2</sup>
console-vue
npx fuels@{{fuels}} build --deploy

Using the --deploy flag will additionally:

  1. Auto-start a short-lived fuel-core node if needed (docs)
  2. Run deploy on that node

This is useful when working with contracts because a contract's ID is generated only on deployment.

fuels deploy

console-vue
npx fuels@{{fuels}} deploy

The fuels deploy command does two things:

  1. Deploy all Sway contracts under workspace.
  2. Saves their deployed IDs to:
    • ./src/sway-programs-api/contract-ids.json
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:

Proxy Contracts Deployment

Automatic deployment of proxy contracts can be enabled in Forc.toml.

For more info, please check these docs:

fuels dev

console-vue
npx fuels@{{fuels}} dev

The fuels dev command does three things:

  1. Auto-start a short-lived fuel-core node (docs)
  2. Runs build and deploy once at the start
  3. Watches your Forc workspace and repeats the previous step on every change

In dev mode, every time you update a contract on your Forc workspace, we re-generate type definitions and factory classes for it, following your pre-configured output 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.

fuels node

console-vue
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}

fuels typegen

Manually generates type definitions and factory classes from ABI JSON files.

console-vue
npx fuels@{{fuels}} help typegen
console
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:

fuels versions

Check for version incompatibilities between your Fuel Toolchain component versions, matching them against the ones supported by the Typescript SDK version that you have.

console-vue
npx fuels@{{fuels}} versions
console-vue
┌───────────┬───────────┬────────────────┬─────────────┐
│           │ Supported │ Yours / System │ System Path │
├───────────┼───────────┼────────────────┼─────────────┤
│ Forc      │ {{forc}}    │ {{forc}}         │ forc        │
├───────────┼───────────┼────────────────┼─────────────┤
│ Fuel-Core │ {{fuelCore}}    │ {{fuelCore}}         │ fuel-core   │
└───────────┴───────────┴────────────────┴─────────────┘

You have all the right versions! ⚡