Exploring the Leo programming language: a comprehensive guide

HEORHII YABLONSKYI
4 min readDec 17, 2023

Hey there, I’m Heorhii, and I’m thrilled to take you on a journey through the fascinating realm of the Leo programming language. Let’s dive into this guide together, unlocking the potential of a functional, statically-typed language tailored for crafting private applications.

Overview

Leo isn’t just a programming language; it’s a bridge to a new era of privacy-centric applications. Imagine a language that abstracts low-level cryptographic intricacies, allowing seamless integration of privacy into your applications. Leo achieves this by compiling to circuits, making zero-knowledge proofs not just theoretical but practical.

Influenced by languages like JavaScript, Scala, and Rust, Leo prioritizes readability and ease-of-use. Developers can leverage tools for circuit sanity checks, including unit tests, integration tests, and console functions.

Note: Leo is currently in its alpha stage, so expect exciting developments and potential breaking changes.

Advantages of Leo:

  1. Privacy by default: Leo prioritizes privacy, ensuring your applications are inherently secure.
  2. Developer-friendly syntax: influenced by popular languages, Leo’s syntax promotes readability and ease of coding.
  3. Zk proofs: Leo compiles to circuits, making zero-knowledge proofs a practical reality.
  4. Robust testing tools: enjoy unit tests, integration tests, and console functions for circuit sanity checks.

Let’s consider the build guide:

1. Install Rust. To embark on your Leo journey, first, ensure Rust is set up.

Use rustup for a hassle-free installation:

# macOS or Linux
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

For a more hands-on approach, build Leo from the source code:

# Download the source code
git clone https://github.com/AleoHQ/leo
cd leo

# Install 'leo'
$ cargo install --path .

Now, unleash Leo’s power in your terminal with a simple command:

leo

2. Quick start. Let’s create a new Leo project and witness its magic:

# Create a new project named 'hello-world'
leo new hello-world
cd hello-world

# Build, set up, prove, and verify
leo run

Voila! You’ve just executed your maiden Leo program. The possibilities are endless.

More info you can find here:

The Leo Command Line Interface

The Leo CLI, bundled with the Leo compiler, empowers you to interact seamlessly. Here’s a glimpse:

  1. Installation. Install Leo globally:
cargo install --path .

2. Global flags:

  • -d, --debug: Enables debugging mode
  • -h, --help: Prints help information
  • -V, --version: Prints version information

3. List of commands:

Run leo --help to see the full list of commands. Here are a few:

  • example: Create a new Leo package from an example program.
  • new: Create a new Leo package in a new directory.
  • build: Compile the current package as a program.
  • run: Run a program with input variables.
  • execute: Execute a program with input variables.
  • clean: Clean the output directory.
  • update: Update to the latest version of Leo.
  • account: Create a new Aleo account.

4. leo example. Explore examples with:

leo example

Choose from programs like a public lottery, Tic-Tac-Toe, custom tokens, and more.

You can find the examples also in the list on Aleo Playground https://play.leo-lang.org/

5. leo new. Create a new Leo package:

leo new my-package

Follow snake_case naming conventions.

6. leo build (deprecated). Compile your program:

leo build

Generate Aleo instructions for verification.

7. leo run. Run your program:

leo run my-transition

Simulate your transition function with inputs. Use this command to run your program before executing it.

8. leo execute. Execute your program:

leo execute my-transition

Generate a transaction object.

9. leo clean. Clean the build directory:

leo clean

10. leo update. Update Leo:

leo update

11. leo account. Manage Aleo accounts:

leo account new

# Output:
Private Key APrivateKey1zkp...
View Key AViewKey1...
Address aleo1...

Generate a new Aleo account with a private key, view key, and address.

To import an existing Aleo account, run:

leo account import {$PRIVATE_KEY}

To create a new account and save it to your .env file, run:

leo account new --write

To list all options

leo account --help

# Output:
Create a new Aleo account
Usage: leo account [OPTIONS] <COMMAND>
Commands:
new Generates a new Aleo account
import Derive an Aleo account from a private key
help Print this message or the help of the given subcommand(s)
Options:
-d Print additional information for debugging
-q Suppress CLI output
--path <PATH> Optional path to Leo program root folder
-h, --help Print help

More info you can find here:

Ready to explore the programming language designed for a private future? Let’s uncover the wonders of Leo together!

Leo documentation:

To know more, join now!
Aleo Twitter
Aleo Discord
Aleo Website

Prepared by Colliseum

--

--