Skip to main content
The leo add command adds dependencies to your Leo project, either from the Aleo network or from local directories.

Syntax

Arguments

string
required
The dependency name. Can be specified with or without .aleo suffix.Examples:
  • credits.aleo
  • credits (automatically adds .aleo)

Options

string
Path to local dependency directory. Mutually exclusive with --network.
boolean
Fetch dependency from the network. Mutually exclusive with --local.
number
Expected edition of the program.
DO NOT USE unless you know what you are doing. Incorrect editions can cause build failures.
boolean
default:false
Add as a development dependency. Dev dependencies are only used during testing.

Examples

Add Network Dependency

Output:
Updates program.json:

Add Network Dependency (Short Syntax)

Automatically appends .aleo:

Add Local Dependency

Output:
Updates program.json:

Add with Specific Edition

Updates program.json:

Add Development Dependency

Updates program.json:
Development dependencies are only included when building tests with leo test or leo build --build-tests.

Overwrite Existing Dependency

Output:

Dependency Types

Network Dependencies

Fetched from the Aleo network:
Characteristics:
  • Downloaded during build
  • Cached for performance
  • Must be deployed on the network
  • Automatically updated on rebuild

Local Dependencies

Referenced from local filesystem:
Characteristics:
  • 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, your program.json looks like:

Using Dependencies

After adding dependencies, import them in your Leo code:

Build Process

When you run leo build:
  1. Dependency Resolution:
    • Reads program.json
    • Downloads network dependencies
    • Locates local dependencies
  2. Dependency Build:
    • Builds dependencies in dependency order
    • Caches network dependencies
    • Compiles local dependencies from source
  3. Main Program Build:
    • Compiles main program with dependencies available
    • Links to dependency bytecode

Dependency Graph

Leo automatically resolves dependency graphs:
Build order: creditshelpermy_libmy_program

Common Patterns

Standard Library Dependencies

The credits.aleo program is commonly used for:
  • Token transfers
  • Fee payments
  • Balance queries

Multi-Project Workspace

Test Dependencies

Use in tests:

Dependency Caching

Network dependencies are cached:
Cache behavior:
  • Dependencies downloaded once
  • Reused across projects
  • Updated on leo build --no-cache

Troubleshooting

Dependency Not Found on Network

Ensure:
  1. Program is deployed on the network
  2. Program name is correct
  3. Network endpoint is accessible

Local Dependency Not Found

Check:
  1. Path is correct (relative or absolute)
  2. Directory contains valid Leo project
  3. program.json exists in dependency

Circular Dependencies

Restructure your code:
  1. Extract shared logic to common dependency
  2. Remove circular references
  3. Use dependency injection patterns

Invalid Program Name

Program names must:
  • End with .aleo
  • Contain only alphanumeric characters and underscores
  • Start with a letter
Valid: my_program.aleo, token123.aleo Invalid: my-program.aleo, 123token.aleo

Version Conflicts

If dependencies require different Leo versions:
Solutions:
  1. Update dependency to match Leo version
  2. Use compatible dependency version
  3. 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

Update README.md:

5. Version Control

Commit program.json but not cached dependencies:

Next Steps