Skip to main content
The leo build command compiles Leo programs into Aleo bytecode, processes dependencies, and generates the Application Binary Interface (ABI).

Syntax

Options

Network Options

string
Network type: mainnet, testnet, or canary. Defaults to testnet.
string
Endpoint URL for network dependencies. Defaults to https://api.explorer.provable.com/v1.

Build Options

boolean
default:false
Enables offline mode. Prevents network requests for dependencies.
boolean
default:false
Don’t use the dependency cache. Forces re-download of dependencies.
boolean
default:false
Don’t use local source code for dependencies. Use network versions instead.
boolean
default:false
Build tests along with the main program and dependencies.

Compiler Options

boolean
default:true
Enable dead code elimination in the compiler.
number
default:10
Maximum depth for type checking nested conditionals.
boolean
default:false
Disable type checking of nested conditional branches in finalize scope.

Debug Options

boolean
default:false
Enable spans in AST snapshots for debugging.
boolean
default:false
Write an AST snapshot immediately after parsing.
boolean
default:false
Write AST snapshots for all compiler phases.
string
Comma-separated list of passes whose AST snapshots to capture.

Examples

Basic Build

Output:

Build with Tests

Build Without Cache

Use --no-cache when you want to force re-download of network dependencies.

Build with AST Snapshots

Generates AST snapshots in outputs/ for each compiler pass.

Build for Specific Network

Build Output

The build process creates:

main.aleo

Compiled Aleo bytecode:

main.abi.json

ABI specification for programmatic interaction:

Program Size Limits

Leo enforces a maximum program size:
  • Maximum size: 10 MB (10,485,760 bytes)
  • Programs exceeding this limit will fail to build
If your program exceeds 8 MB (80% of the limit), you’ll receive a warning to optimize your code.

Compiler Passes

The Leo compiler runs through multiple passes:
  1. Parsing - Convert source to AST
  2. Symbol Resolution - Resolve identifiers
  3. Type Checking - Validate types
  4. Loop Unrolling - Unroll loops to fixed iterations
  5. Monomorphization - Convert generic types to concrete types
  6. Flattening - Flatten complex expressions
  7. Dead Code Elimination - Remove unused code
  8. Code Generation - Generate Aleo instructions

Checksum Verification

After building, Leo displays the program checksum:
Use this checksum to verify program integrity and ensure consistent builds.

Dependencies

Leo automatically builds dependencies listed in program.json:
Dependencies are built in dependency order (child before parent) and cached for performance.

Troubleshooting

Compiler Version Mismatch

If you see a warning about compiler version mismatch:
Update program.json to match your Leo version.

Network Dependencies Failed

If network dependencies fail to download:
Or check your --endpoint configuration.

Next Steps