Commands
The fuels CLI consists of a couple of commands.
fuels init
npx fuels@0.92.0 help initOptions:
-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 generationCreating a sample fuel.config.ts file:
npx fuels@0.92.0 init --contracts ./my-contracts/* --output ./src/sway-contracts-apiUsing Forc workspaces? Try this instead:
npx fuels@0.92.0 init --workspace ./sway-programs --output ./src/sway-programs-apiThis 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.jsonSee more
fuels build
npx fuels@0.92.0 help buildOptions:
--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 helpExamples:
npx fuels@0.92.0 build- Build all Sway programs under your
workspaceusingforc1 - Generate types for them using
fuels-typegen2
npx fuels@0.92.0 build --deployUsing the --deploy flag will additionally:
- Auto-start a short-lived
fuel-corenode if needed (docs) - Run
deployon that node
This is useful when working with contracts because a contract's ID is generated only on deployment.
fuels deploy
npx fuels@0.92.0 deployNote
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 command instead.
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:
import { SampleAbi__factory } 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 = SampleAbi__factory.connect(contractsIds.sample, wallet);
const { value } = await contract.functions.return_input(1337).dryRun();
expect(value.toHex()).toEqual(toHex(1337));For a complete example, see:
fuels dev
npx fuels@0.92.0 devThe fuels dev command does three things:
- Auto-start a short-lived
fuel-corenode (docs) - Runs
buildanddeployonce at the start - Watches your Forc workspace and repeats the previous step on every change
In
devmode, every time you update a contract on your Forcworkspace, we re-generate type definitions and factory classes for it, following your pre-configuredoutputdirectory. 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
npx fuels@0.92.0 nodeThe fuels node command starts a short-lived fuel-core node (docs).
fuels typegen
Manually generates type definitions and factory classes from ABI JSON files.
npx fuels@0.92.0 help typegenOptions:
-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 messagesFor 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.
npx fuels@0.92.0 versions┌───────────┬───────────┬────────────────┬─────────────┐
│ │ Supported │ Yours / System │ System Path │
├───────────┼───────────┼────────────────┼─────────────┤
│ Forc │ 0.61.2 │ 0.61.2 │ forc │
├───────────┼───────────┼────────────────┼─────────────┤
│ Fuel-Core │ 0.31.0 │ 0.31.0 │ fuel-core │
└───────────┴───────────┴────────────────┴─────────────┘
You have all the right versions! ⚡