FuelLabs/fuels-ts · warning · Error

Contract not found!

Error message

Contract not found!

What it means

Thrown by the deployConfig callback in the demo fuels config when no deployed contract in `options.contracts` matches the `MY_FIRST_DEPLOYED_CONTRACT_NAME` constant. The callback needs the matching contract's `contractId` to populate a storage slot, so it refuses to proceed without one. This is example code, not library runtime logic — the constant ships as an empty string and is meant to be filled in.

Source

Thrown at apps/demo-fuels/fuels.config.full.ts:69

  // Default: []
  forcBuildFlags: ['--release'],
  // #endregion forcBuildFlags

  // #region deployConfig-fn
  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,
        },
      ],
    };
  },
  // #endregion deployConfig-fn

  // #region onBuild

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Set `MY_FIRST_DEPLOYED_CONTRACT_NAME` to the exact Sway contract name (the `project.name` in `Forc.toml`, also the generated TypeScript class name) of a contract in the configured workspace.
  2. Log `options.contracts.map(c => c.name)` first to see the available names, then copy one into the constant.
  3. If you do not need storage-slot initialization, replace the `deployConfig` callback with an object (`deployConfig: {}`) or remove it entirely.

Example fix

// before
const MY_FIRST_DEPLOYED_CONTRACT_NAME = '';
// after
const MY_FIRST_DEPLOYED_CONTRACT_NAME = 'my_contract'; // must match a contract name in options.contracts
Defensive patterns

Strategy: validation

Validate before calling

// inside deployConfig, before find():
const { contracts } = options;
const validNames = contracts.map((c) => c.name);
if (!validNames.includes(MY_FIRST_DEPLOYED_CONTRACT_NAME)) {
  throw new Error(
    `Contract '${MY_FIRST_DEPLOYED_CONTRACT_NAME}' not found. Available: ${validNames.join(', ')}`
  );
}

Try / catch

try {
  // deployConfig body
} catch (e) {
  if (e.message === 'Contract not found!') {
    throw new Error(`Contract not found. Available: ${options.contracts.map(c => c.name).join(', ')}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `fuels deploy` (or the demo's build/deploy flow) while `MY_FIRST_DEPLOYED_CONTRACT_NAME` is still the default empty string, or after renaming a Sway contract so the constant no longer matches any `name` in `options.contracts`. Also fires if the workspace has zero contracts deployed.

Common situations: Copying the demo config as a starting template but forgetting to set the constant; renaming a contract project folder without updating the constant; pointing `contracts:` globs at a directory whose compiled contract names differ from the constant.

Related errors


AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12). Data as JSON: /api/errors/c6b180249eb8a4fd. Report an issue: GitHub.