leo add command adds dependencies to your Leo project, either from the Aleo network or from local directories.
Syntax
Arguments
The dependency name. Can be specified with or without
.aleo suffix.Examples:credits.aleocredits(automatically adds.aleo)
Options
Path to local dependency directory. Mutually exclusive with
--network.Fetch dependency from the network. Mutually exclusive with
--local.Expected edition of the program.
Add as a development dependency. Dev dependencies are only used during testing.
Examples
Add Network Dependency
program.json:
Add Network Dependency (Short Syntax)
.aleo:
Add Local Dependency
program.json:
Add with Specific Edition
program.json:
Add Development Dependency
program.json:
Development dependencies are only included when building tests with
leo test or leo build --build-tests.Overwrite Existing Dependency
Dependency Types
Network Dependencies
Fetched from the Aleo network:- Downloaded during build
- Cached for performance
- Must be deployed on the network
- Automatically updated on rebuild
Local Dependencies
Referenced from local filesystem:- Built from source code
- Changes reflected immediately
- Must exist at specified path
- Ideal for development
Dependency Locations
Dependency paths can be:Relative Paths
Absolute Paths
Program Structure
After adding dependencies, yourprogram.json looks like:
Using Dependencies
After adding dependencies, import them in your Leo code:Build Process
When you runleo build:
-
Dependency Resolution:
- Reads
program.json - Downloads network dependencies
- Locates local dependencies
- Reads
-
Dependency Build:
- Builds dependencies in dependency order
- Caches network dependencies
- Compiles local dependencies from source
-
Main Program Build:
- Compiles main program with dependencies available
- Links to dependency bytecode
Dependency Graph
Leo automatically resolves dependency graphs:credits → helper → my_lib → my_program
Common Patterns
Standard Library Dependencies
credits.aleo program is commonly used for:
- Token transfers
- Fee payments
- Balance queries
Multi-Project Workspace
Test Dependencies
Dependency Caching
Network dependencies are cached:- Dependencies downloaded once
- Reused across projects
- Updated on
leo build --no-cache
Troubleshooting
Dependency Not Found on Network
- Program is deployed on the network
- Program name is correct
- Network endpoint is accessible
Local Dependency Not Found
- Path is correct (relative or absolute)
- Directory contains valid Leo project
program.jsonexists in dependency
Circular Dependencies
- Extract shared logic to common dependency
- Remove circular references
- Use dependency injection patterns
Invalid Program Name
- End with
.aleo - Contain only alphanumeric characters and underscores
- Start with a letter
my_program.aleo, token123.aleo
Invalid: my-program.aleo, 123token.aleo
Version Conflicts
If dependencies require different Leo versions:- Update dependency to match Leo version
- Use compatible dependency version
- Update Leo CLI
Best Practices
1. Use Specific Editions
For production, pin dependency editions:2. Local for Development, Network for Production
3. Separate Dev Dependencies
4. Document Dependencies
UpdateREADME.md:
5. Version Control
Commitprogram.json but not cached dependencies: