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
Build with Tests
Build Without Cache
Use
--no-cache when you want to force re-download of network dependencies.Build with AST Snapshots
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
Compiler Passes
The Leo compiler runs through multiple passes:- Parsing - Convert source to AST
- Symbol Resolution - Resolve identifiers
- Type Checking - Validate types
- Loop Unrolling - Unroll loops to fixed iterations
- Monomorphization - Convert generic types to concrete types
- Flattening - Flatten complex expressions
- Dead Code Elimination - Remove unused code
- Code Generation - Generate Aleo instructions
Checksum Verification
After building, Leo displays the program checksum:Dependencies
Leo automatically builds dependencies listed inprogram.json:
Troubleshooting
Compiler Version Mismatch
If you see a warning about compiler version mismatch:program.json to match your Leo version.
Network Dependencies Failed
If network dependencies fail to download:--endpoint configuration.