Developer Way #2. Learn Leo together

Romualds Bahvalovs
5 min readJan 28, 2023

--

Step two. How to create a program using Leo.

Hi everyone, today we continue to learn the Leo programming language. In this article we will install sublime text and create our first program. I would like to remind you that Leo is a programming language created by Aleo to work with zero-knowledge proof technology. That is, using this programming language, you can create fully private applications. In the last article we installed the necessary programs to work with Leo, if you haven’t seen it, be sure to read it.

Installing sublime text.

To do this, we go to the Aleo website (Aleo.org). Click the “For developers” button — “Aleo Developer Docs”.

Here we need to find Developer Resources and go to GitHub.

Here we have full instructions on how to download sublime text. First, we download and install this program using the link from the article.

Installation is very simple, so I will not describe it in this article. If you don’t understand something, you can watch a detailed video on my YouTube channel: https://youtu.be/7fA-PpwFMio.

Now we open sublime text and press ctrl + shift + p. Enter Install Package Control and press enter.

After that, press ctrl + shift + p again. Select Package Control: Install Package and look for LSP and press enter.

After successful installation, you will see the following text in the program:

The last step is to install the LSP-leo. To do this, repeat the steps in the previous step. Only instead of LSP, install LSP-leo. That’s it, we have successfully installed sublime text.

What do we do next? Now we get to the fun part. We create our first program that uses ZKP. To do this we need to open Git and enter the following commands. Leo new hello. Hello is the name of our first program.

Now we write cd hello. So, we have opened our program. To run it we type: leo run main. When we write this code, we start the file main.

After executing the program, we get this result: 3u32. The number 3 is the value of the variable. U means the number is unsigned. 32 means that the number is 32 bits.

So… let’s see what the program looks like. To do this, we need to find the folder where it is located. In my case you can see the location in the screenshot.

What do we see? The program.json file — this is where your program manifest is located. The readme file — here is the description of your program. In the src folder is the file main. This is the file we started when we entered the command leo run main. This file contains your program. And the last file is in the inputs folder. If the file has the extension «in», that means it stores the inputs.

Let’s open each file.

The program.json file. Here we see the program name, version, private key and address.

Let’s open the input data, the main file and run the program.

In the documentation we see the following explanation: program hello.aleo defines the name of the program inside the Leo file. The program ID must match the program.json manifest file. The keyword transition indicates a transition function definition in Leo. Our hello main function takes an input a with type u32 and public visibility, and an input b with type u32 and private visibility (by default). The program returns one result with type u32. Inside the main function we declare a variable c with type u32 and set it equal to the addition of variables a and b. Leo’s compiler will check that the types of a and b are equal and that the result of the addition is type u32. Last, we return the variable c. Leo will check that c’s type matches the function return type u32.

So in this program we add up 2 variables. We can change the input data and run the program again.

Yes, the result is correct.

Today we created our first program using ZKP technology. I think the first steps were quite simple. In the next article we will talk about variables. I want to remind you that you can watch a more detailed video on this topic on my channel: https://youtu.be/7fA-PpwFMio. See you in the next articles!

--

--

No responses yet