Skip to content

Config File

Here, you can learn more about all configuration options.

workspace

Relative directory path to Forc workspace.

ts
workspace: './sway-programs',
See code in context

The property workspace is incompatible with contracts, predicates, and scripts.

contracts

List of relative directory paths to Sway contracts.

ts
contracts: ['./sway-programs/contracts'],
See code in context

The property contracts is incompatible with workspace.

predicates

List of relative directory paths to Sway predicates.

ts
predicates: ['./sway-programs/predicates'],
See code in context

The property predicates is incompatible with workspace.

scripts

List of relative directory paths to Sway scripts.

ts
scripts: ['./sway-programs/scripts'],
See code in context

The property scripts is incompatible with workspace.

output

Relative directory path to use when generating Typescript definitions.

ts
output: './src/sway-programs-api',
See code in context

providerUrl

The URL to use when deploying contracts.

ts
// Default: http://127.0.0.1:4000/v1/graphql
providerUrl: 'http://network:port/v1/graphql',
See code in context

When autostartFuelCore property is set to true, the providedUrl is overridden by that of the local short-lived fuel-core node started by the fuels dev command.

privateKey

Wallet private key, used when deploying contracts.

This property should ideally come from env — process.env.MY_PRIVATE_KEY.

ts
privateKey: '0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298',
See code in context

When autostartFuelCore property is set to true, the privateKey is overridden with the consensusKey of the local short-lived fuel-core node started by the fuels dev command.

snapshotDir

Relative path to directory containing custom configurations for fuel-core, such as:

  • chainConfig.json
  • metadata.json
  • stateConfig.json

This will take effect only when autoStartFuelCore is true.

ts
snapshotDir: './my/snapshot/dir',
See code in context

autoStartFuelCore

When set to true, it will automatically:

  1. Starts a short-lived fuel-core node as part of the fuels dev command
  2. Override property providerUrl with the URL for the recently started fuel-core node
ts
autoStartFuelCore: true,
See code in context

If set to false, you must spin up a fuel-core node by yourself and set the URL for it via providerUrl.

fuelCorePort

Port to use when starting a local fuel-core node.

ts
// Default: first free port, starting from 4000
fuelCorePort: 4000,
See code in context

forcBuildFlags

Sway programs are compiled in debug mode by default.

Here you can customize all build flags, e.g. to build programs in release mode.

ts
// Default: []
forcBuildFlags: ['--release'],
See code in context

Check also:

deployConfig

You can supply a ready-to-go deploy configuration object:

ts
deployConfig: {},
See code in context

Or use a function for crafting dynamic deployment flows:

  • If you need to fetch and use configs or data from a remote data source
  • If you need to use IDs from already deployed contracts — in this case, we can use the options.contracts property to get the necessary contract ID. For example:
ts
deployConfig: async (options: ContractDeployOptions) => {
  // ability to fetch data remotely
  await Promise.resolve(`simulating remote data fetch`);

  // get contract by name
  const { contracts } = options;

  const contract = contracts.find(({ name }) => {
    const found = name === MY_FIRST_DEPLOYED_CONTRACT_NAME;
    return found;
  });

  if (!contract) {
    throw new Error('Contract not found!');
  }

  return {
    storageSlots: [
      {
        key: '0x..',
        /**
         * Here we could initialize a storage slot,
         * using the relevant contract ID.
         */
        value: contract.contractId,
      },
    ],
  };
},
See code in context

onSuccess

Pass a callback function to be called after a successful run.

Parameters:

  • event — The event that triggered this execution
  • config — The loaded config (fuels.config.ts)
ts
onSuccess: (event: CommandEvent, config: FuelsConfig) => {
  console.log('fuels:onSuccess', { event, config });
},
See code in context

onFailure

Pass a callback function to be called in case of errors.

Parameters:

  • error — Original error object
  • config — The loaded config (fuels.config.ts)
ts
onFailure: (error: Error, config: FuelsConfig) => {
  console.log('fuels:onFailure', { error, config });
},
See code in context

useBuiltinForc

Opt-in or out from using built-in forc binaries.

When not supplied, will default to using the system binaries.

If system binaries are absent, print a warning and use built-in ones instead.

ts
// Default: undefined
useBuiltinForc: false,
See code in context

Check also:

useBuiltinFuelCore

Opt-in or out from using built-in fuel-core binaries.

When not supplied, will default to using the system binaries.

If system binaries are absent, print a warning and use built-in ones instead.

ts
// Default: undefined
useBuiltinFuelCore: false,
See code in context

Check also:

Loading environment variables

If you want to load environment variables from a .env file, you can use the dotenv package.

First, install it:

sh
pnpm install dotenv
sh
npm install dotenv

Then, you can use it in your fuels.config.ts file:

ts
import { createConfig } from 'fuels';
import dotenv from 'dotenv';
import { NODE_URL } from '@/lib'

dotenv.config({
  path: ['.env.local', '.env'],
});

const fuelCorePort = +(process.env.NEXT_PUBLIC_FUEL_NODE_PORT as string) || 4000;

export default createConfig({
  workspace: './sway-programs',
  output: './src/sway-api',
  fuelCorePort,
  providerUrl: NODE_URL,
});
See code in context