Import Statement
Leo programs can import other programs to reuse functionality. Imports are declared before the program scope:Import Syntax
The basic import syntax is:Using Imported Programs
Once imported, you can reference types and call functions from imported programs:Accessing Imported Types
Access types from imported programs using dot notation:Calling Imported Functions
While Leo supports imports for type definitions, calling external program functions typically happens through the Aleo VM’s program composition at runtime.Built-in Programs
Credits Program
Thecredits.aleo program is available by default:
Import Resolution
Leo resolves imports in the following order:- Local programs: Programs in your project
- Dependencies: Programs specified in
program.json - Published programs: Programs deployed on the Aleo network
Project Structure
Dependencies Configuration
Specify external dependencies inprogram.json:
Import Patterns
Wrapper Pattern
Wrap imported functionality with your own interface:Adapter Pattern
Adapt imported types to your program’s needs:Composition Pattern
Combine multiple imported programs:Import Limitations
No Wildcard Imports
Leo does not support wildcard imports:No Selective Imports
You must import the entire program, not individual items:No Aliasing
Leo does not support import aliases:Best Practices
1. Explicit Imports
Import only what you need:2. Document Dependencies
Comment on why imports are needed:3. Version Dependencies
Specify exact versions inprogram.json:
4. Validate Imported Data
Always validate data from imported programs:Circular Dependencies
Leo does not allow circular dependencies:Resolving Circular Dependencies
Create a common base program:Standard Library Patterns
Common patterns for importing standard functionality:Token Standard
NFT Standard
Local Development
When developing locally, ensure imported programs are available:Deployment Considerations
When deploying programs with imports:- Deploy dependencies first: Imported programs must be deployed before programs that import them
- Verify program IDs: Ensure imported program IDs match deployed versions
- Network consistency: All programs must be on the same network (mainnet, testnet, etc.)
Example: Multi-Program Application
Complete example using multiple imports:Next Steps
Programs
Learn about program structure
Records
Work with imported records
Data Types
Understand type compatibility
Functions
Use imported types in functions