Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link

Icon LinkCommands

The fuels CLI consists of a couple of commands.

Icon Linkfuels init

npx fuels@0.94.2 help init
Options:
  -w, --workspace <path>          Relative dir path to Forc workspace
  -c, --contracts <path|global>   Relative path/globals to  Contracts
  -s, --scripts <path|global>     Relative path/globals to  Scripts
  -p, --predicates <path|global>  Relative path/globals to  Predicates
  -o, --output <path>             Relative dir path for Typescript generation

Creating a sample fuel.config.ts file:

npx fuels@0.94.2 init --contracts ./my-contracts/* --output ./src/sway-contracts-api

Using Forc workspaces Icon Link? Try this instead:

npx fuels@0.94.2 init --workspace ./sway-programs --output ./src/sway-programs-api

This will give you a minimal configuration:

import { createConfig } from 'fuels';
 
export default createConfig({
  workspace: './sway-programs', // forc workspace
  output: './src/sway-programs-api',
});

In a nutshell:

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

Icon LinkSee more

Icon Linkfuels build

npx fuels@0.94.2 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@0.94.2 build
  1. Build all Sway programs under your workspace using forc 1 Icon Link
  2. Generate types for them using fuels-typegen 2
npx fuels@0.94.2 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
Icon InfoCircle

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

Icon Linkfuels deploy

npx fuels@0.94.2 deploy
Icon InfoCircle

[!NOTE] Note We recommend using the fuels deploy command only when you are deploying contracts to a local node. If you are deploying contracts to a live network like the Testnet, we recommend using the forc deploy Icon Link command instead.

Additionally, the maximum contract deployment size supported by the SDK is 100 KB. The SDK will throw an error for contracts larger than this size.

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
{
  "myContract1": "0x..",
  "myContract2": "0x.."
}

Use it when instantiating your contracts:

import { Sample } from './sway-programs-api';
import contractsIds from './sway-programs-api/contract-ids.json';
 
/**
  * Get IDs using:
  *   contractsIds.<my-contract-name>
  */
 
const wallet = new Wallet.fromPrivateKey(process.env.PRIVATE_KEY);
const contract = new Sample(contractsIds.sample, wallet);
 
const { value } = await contract.functions.return_input(1337).dryRun();
 
expect(value.toHex()).toEqual(toHex(1337));

For a complete example, see:

Icon Linkfuels dev

npx fuels@0.94.2 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
Icon InfoCircle

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.

Icon Linkfuels node

npx fuels@0.94.2 node

The fuels node command starts a short-lived fuel-core node (docs ).

Icon Linkfuels typegen

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

npx fuels@0.94.2 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:

Icon Linkfuels versions

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

npx fuels@0.94.2 versions
┌───────────┬───────────┬────────────────┬─────────────┐
│           │ Supported │ Yours / System │ System Path │
├───────────┼───────────┼────────────────┼─────────────┤
│ Forc      │ 0.63.1    │ 0.63.1         │ forc        │
├───────────┼───────────┼────────────────┼─────────────┤
│ Fuel-Core │ 0.34.0    │ 0.34.0         │ fuel-core   │
└───────────┴───────────┴────────────────┴─────────────┘

You have all the right versions! ⚡