Skip to main content

The Leo Command Line Interface

The Leo CLI is a command line interface tool that comes equipped with the Leo compiler.

Installation

Install Leo

Global Flags

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

List of Commands:

tip

You can print the list of commands by running leo --help

  • 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.
  • deploy - Deploy a program.
  • clean - Clean the output directory.

leo new

To create a new package, run:

leo new {$NAME}

Valid package names are snake_case: lowercase letters and numbers separated by underscores. This command will create a new directory with the given package name. The new package will have a directory structure as follows:

package-name/
├── program.json # Your program manifest
├── README.md # Your program description
├── build/
├── inputs/
│ ├── hello.in # Your program inputs
└── src/
└── main.leo # Your program file

leo build

To compile your program and verify that it builds properly, run:

leo build

This will populate the directory build/ (creating it if it doesn't exist) with an Aleo instructions file .aleo.

console output:
     Leo ✅ Compiled 'main.leo' into Aleo instructions
Leo ✅ Built 'hello.aleo' (in "/hello/build")

leo run

To execute a Leo transition function using inputs from the program input .in file.

leo run {$TRANSITION}

To execute a Leo transition function with inputs from the command line. {$INPUTS} should be a list of inputs to the program separated by spaces.

leo run {$TRANSITION} {$INPUTS}
console output:
 Leo ✅ Compiled 'main.leo' into Aleo instructions
⏳ Compiling 'hello.aleo'...

• Loaded universal setup (in 100 ms)
• Built 'main' (in 1000 ms)

Leo ✅ Built 'hello.aleo' (in "/hello/build")
• Loaded universal setup (in 100 ms)
🚀 Executing 'hello.aleo/main'...

• Executing 'hello.aleo/main'...
• Executed 'main' (in 1000 ms)

➡️ Output

• 3u32

Leo ✅ Executed 'hello.aleo/main' (in "/hello/build")

Testnet3 Development Endpoints

The server will start at the following endpoint:

🌐 Server is running at http://0.0.0.0:4180

Latest Block Height

Returns the number of blocks in the canonical chain.

http://localhost:4180/testnet3/latest/block/height

Latest Block Hash

Returns the block hash from the head of the canonical chain.

http://localhost:4180/testnet3/latest/block/hash

Latest Block

Returns the block from the head of the canonical chain.

http://localhost:4180/testnet3/latest/block

Get Block

Returns the block given the block height.

http://localhost:4180/testnet3/block/{height}

Getting records belonging to an account

You can retrieve records in three different ways, depending on what type of records you want to query. You will need your ViewKey at your disposal. There are two types of records, spent and unspent, we will talk about these later on. You can see the list of the endpoints associated below:

Get All Owned Records

GET /testnet3/records/all

This endpoint retrieves all the records belonging to a given ViewKey.

curl --location --request GET 'localhost:4180/testnet3/records/all' -H 'Content-Type: application/json' -d '"AViewKey1iAf6a7fv6ELA4ECwAth1hDNUJJNNoWNThmREjpybqder"'

Get All Spent Records

GET /testnet3/records/spent

This endpoint retrieves only the spent records belonging to a given ViewKey.

curl --location --request GET 'localhost:4180/testnet3/records/spent' -H 'Content-Type: application/json' -d '"AViewKey1iAf6a7fv6ELA4ECwAth1hDNUJJNNoWNThmREjpybqder"'

Get All Unspent Records

GET /testnet3/records/unspent

This endpoint retrieves only the unspent records belonging to a given ViewKey.

curl --location --request GET 'localhost:4180/testnet3/records/unspent' -H 'Content-Type: application/json' -d '"AViewKey1iAf6a7fv6ELA4ECwAth1hDNUJJNNoWNThmREjpybqder"'

leo deploy

To deploy a program to Aleo Testnet3 run.

leo deploy

leo clean

To clean the build directory, run:

leo clean
console output:
  Leo cleaned the build directory (in "/build/")