Quick Start
This guide will walk you through creating your first Leo program. You’ll learn how to create a new project, understand the project structure, write Leo code, and run your program.Make sure you have installed Leo before continuing with this guide.
Create Your First Program
Create a new Leo project
Use the Leo CLI to create a new project:This creates a new directory called
helloworld with a complete Leo project structure.Understanding the Default Program
Let’s look at the default program created insrc/main.leo:
Program Structure
- Program declaration:
program helloworld.aleodefines the program name - Function:
fn mainis the entry point of the program - Parameters:
aandbare inputs (both publicu32unsigned 32-bit integers) - Return type:
-> u32specifies the function returns a 32-bit unsigned integer - Logic: The function simply adds the two inputs and returns the result
All Leo programs must have the
.aleo suffix in their program declaration.Run Your Program
Leo makes it easy to run your program with a single command:- Compiles the program into Aleo instructions
- Executes the
mainfunction with inputs0u32and1u32 - Displays the output
The
leo run command automatically builds your program before running it, so you don’t need to run leo build separately.Try Different Inputs
Let’s experiment with different inputs:60u32.
Build Your Own Program
Now let’s modify the program to do something more interesting.Understanding Leo Commands
Here are the essential Leo CLI commands:Working with Different Data Types
Leo supports various data types. Here’s a more comprehensive example:Key Data Types
- Integers:
u8,u16,u32,u64,u128,i8,i16,i32,i64,i128 - Boolean:
bool - Field elements:
field - Group elements:
group - Address:
address - Records: Custom data structures that represent program state
Records in Leo are special data types that represent ownership and can be used to manage state privately on the Aleo blockchain.
Network Configuration
When creating a new project, you can specify the network:testnet(default)mainnetcanary
Common Command Options
Run with specific network
Build with offline mode
Run with debug output
Quiet mode (suppress output)
Next Steps
Congratulations! You’ve just run your first Leo program. Here’s what to explore next:Language Reference
Learn Leo syntax and language features
Example Programs
Explore more complex Leo programs
Deploy Programs
Learn how to deploy to the Aleo network
Testing Guide
Write tests for your Leo programs
Troubleshooting
Program won’t compile
Make sure:- Your program name matches the directory name
- All functions have proper type annotations
- Syntax is correct (check semicolons, braces, etc.)
”Failed to execute” errors
Common causes:- Incorrect input types (e.g., using
1instead of1u32) - Wrong number of inputs
- Input values that cause assertion failures