FuelLabs/fuels-rs · error

abigen generation failed

Error message

abigen generation failed

What it means

abigen! is a proc macro: it parses the macro input, loads the ABI file(s) from disk, and runs bindings generation (Abigen::generate). Any failure anywhere in that pipeline is collapsed into this single .expect at compile time, so the message alone does not say which step failed.

Source

Thrown at packages/fuels-macros/src/lib.rs:40

/// `ProgramType` is either `Contract`, `Script` or `Predicate`.
///
/// `ABI_SOURCE` is a string literal representing either a path to the JSON ABI
/// file or the contents of the JSON ABI file itself.
///
///```text
/// abigen!(Contract(
///         name = "MyContract",
///         abi = "packages/fuels/tests/contracts/token_ops/out/release/token_ops-abi.json"
///     ));
///```
///
/// More details can be found in the [`Fuel Rust SDK Book`](https://fuellabs.github.io/fuels-rs/latest)
#[proc_macro]
pub fn abigen(input: TokenStream) -> TokenStream {
    let targets = parse_macro_input!(input as MacroAbigenTargets);

    Abigen::generate(targets.into(), false)
        .expect("abigen generation failed")
        .into()
}

#[proc_macro]
pub fn wasm_abigen(input: TokenStream) -> TokenStream {
    let targets = parse_macro_input!(input as MacroAbigenTargets);

    Abigen::generate(targets.into(), true)
        .expect("abigen generation failed")
        .into()
}

/// Used to reduce boilerplate in integration tests.
///
/// More details can be found in the [`Fuel Rust SDK Book`](https://fuellabs.github.io/fuels-rs/latest)
#[proc_macro]
pub fn setup_program_test(input: TokenStream) -> TokenStream {
    let test_program_commands = parse_macro_input!(input as TestProgramCommands);

View on GitHub (pinned to d9a250a518)

Solutions

  1. Run forc build (forc build --release) so the ABI json exists at the path given to abigen!
  2. Fix the path: it resolves relative to the crate root, e.g. "tests/contracts/my_contract/out/release/my_contract-abi.json"
  3. Validate the file is readable, valid JSON (jq empty or similar)
  4. cargo clean and rebuild if stale artifacts are suspected; update fuels to the version matching your forc

Example fix

// before: path does not exist because the contract was never built
abigen!(Contract(name = "MyContract", abi = "out/release/token_ops-abi.json"));

// after: build first, and point at the real artifact
// (shell) forc build --release
abigen!(Contract(name = "MyContract", abi = "tests/contracts/token_ops/out/release/token_ops-abi.json"));
Defensive patterns

Strategy: validation

Validate before calling

# (shell) make sure the ABI exists and is valid JSON before cargo build
forc build --release
test -f tests/contracts/my_contract/out/release/my_contract-abi.json \
  && jq empty tests/contracts/my_contract/out/release/my_contract-abi.json

Prevention

When it happens

Trigger: Compiling a crate whose abigen! references an abi path that does not exist relative to the crate root (commonly out/release/*-abi.json missing because forc build was not run), malformed macro syntax, unreadable or invalid JSON, or ABI constructs the generator does not support.

Common situations: Forgetting to run forc build before cargo build/test; moving or renaming contract directories; wrong relative path; forc/fuels version mismatch.

Related errors


AI-assisted analysis of FuelLabs/fuels-rs@d9a250a518 (2026-08-16). Data as JSON: /api/errors/2ccc6e8c0031d81b. Report an issue: GitHub.