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):
--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'.
- 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
- 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.
- 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.
- 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.
Summary
leo addoverloads 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 adddoes two things (crates/leo/src/cli/commands/add.rs:230-267):--network/-nis a valueless boolean in the mutually-exclusivesourcegroup (alongside--local,--git,--workspace,--edition). It only means "this dependency lives on a live network." Soleo add foo.aleo --network mainnetfails withunexpected argument 'mainnet'.program.json, it performs a verification fetch (CompilationUnit::fetch) to confirm the program exists. The network for that fetch is resolved viaget_network(&None)— it deliberately ignores the CLI and reads only theNETWORKenv var, defaulting totestnetotherwise.The recorded manifest entry is network-agnostic (
location: "network", no network field).NETWORKis 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
--onchain(keep-n), freeing--network <name>to take a value consistent withbuild/deploy. Thread it through asget_network(&self.network). Thenleo add foo.aleo --onchain --network mainnetreads naturally and matches every other command. Breaking change to the flag name.--networkboolean and add--network-name <NAME>(or reuse--endpointsemantics) as a CLI escape hatch threaded into the verification fetch. Non-breaking, but leaves the overloaded--networkin place.--verify) soleo addbecomes a pureprogram.jsonedit with no network dependency at all. The existence check would then happen atleo buildtime, where the network is already meaningful.Option 1 fixes the root cause and aligns
addwith the rest of the CLI.