Skip to content

leo add: --network is a source flag, but the verification network is env-only #29591

Description

@mohammadfawaz

Summary

leo add overloads the word "network" onto two unrelated concepts, which makes it impossible to add a mainnet dependency without setting an environment variable.

Details

For a network dependency, leo add does two things (crates/leo/src/cli/commands/add.rs:230-267):

  1. --network / -n is a valueless boolean in the mutually-exclusive source group (alongside --local, --git, --workspace, --edition). It only means "this dependency lives on a live network." So leo add foo.aleo --network mainnet fails with unexpected argument 'mainnet'.
  2. Before writing the entry to program.json, it performs a verification fetch (CompilationUnit::fetch) to confirm the program exists. The network for that fetch is resolved via get_network(&None) — it deliberately ignores the CLI and reads only the NETWORK env var, defaulting to testnet otherwise.

The recorded manifest entry is network-agnostic (location: "network", no network field). NETWORK is used solely as the target for the pre-flight existence check.

Impact

To add a program that only exists on mainnet, the user must set NETWORK=mainnet — there is no command-line way to do it. The default path warns then hard-errors with a 404 against testnet, which reads as "the program doesn't exist" rather than "you're looking at the wrong network."

Alternatives

  1. Rename the source flag (preferred). Rename the boolean to something like --onchain (keep -n), freeing --network <name> to take a value consistent with build/deploy. Thread it through as get_network(&self.network). Then leo add foo.aleo --onchain --network mainnet reads naturally and matches every other command. Breaking change to the flag name.
  2. Add a separate value flag. Keep the --network boolean and add --network-name <NAME> (or reuse --endpoint semantics) as a CLI escape hatch threaded into the verification fetch. Non-breaking, but leaves the overloaded --network in place.
  3. Skip verification / make it opt-in. Drop the pre-flight fetch (or gate it behind --verify) so leo add becomes a pure program.json edit with no network dependency at all. The existence check would then happen at leo build time, where the network is already meaningful.

Option 1 fixes the root cause and aligns add with the rest of the CLI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working🖥️ CLIAnything related to the Leo CLI.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions