Skip to main content

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

1

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.
2

Navigate to the project directory

3

Explore the project structure

Your new Leo project has the following structure:

Understanding the Default Program

Let’s look at the default program created in src/main.leo:

Program Structure

  • Program declaration: program helloworld.aleo defines the program name
  • Function: fn main is the entry point of the program
  • Parameters: a and b are inputs (both public u32 unsigned 32-bit integers)
  • Return type: -> u32 specifies 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:
This command:
  1. Compiles the program into Aleo instructions
  2. Executes the main function with inputs 0u32 and 1u32
  3. 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:
The output should be 60u32.

Build Your Own Program

Now let’s modify the program to do something more interesting.
1

Create a Fibonacci function

Edit src/main.leo to implement a Fibonacci calculator:
2

Run the Fibonacci program

This calculates the 10th Fibonacci number.

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:
Available networks:
  • testnet (default)
  • mainnet
  • canary

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 1 instead of 1u32)
  • Wrong number of inputs
  • Input values that cause assertion failures

Network connection issues

If you’re having trouble connecting to the network:
This uses a local endpoint instead of the default remote endpoint.