Creating and deploying a transparent and shielded custom Token with Aleo Leo: tutorial

HEORHII YABLONSKYI
4 min readJan 14, 2024

Hey, tech enthusiasts! I’m Heorhii, and I’m thrilled to guide you through the fascinating world of Aleo Leo. In this tutorial, we’ll learn how to create and deploy a transparent and shielded custom token on the Aleo blockchain. Ready to dive in?

We’ll be creating a custom token that operates both transparently and in a shielded manner. This provides users with the flexibility to choose between public and private transactions based on their preferences.

How to run. Before we start building our token, let’s ensure we have Aleo Leo installed. Follow these simple steps:

Leo installation:

  1. Download Leo: Download the latest Leo release using a pre-built installer for your platform.
  2. For MacOS M1 and other platforms, follow the provided links.
  3. Install Leo from source (optional): to access the latest features, you can install Leo from the source code on GitHub.

Install prerequisites:

1. Install Git:

2. Install Rust:

Check the prerequisites:

git --version
cargo --version

Build Leo from source code: You can build and install Leo from the source code as follows:

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

# Build and install
cargo install --path .

That will generate the executable ~/.cargo/bin/leo.

Now to use Leo, in your terminal, run:

leo

IDE Syntax Highlighting: Ensure you have syntax highlighting for Aleo in your preferred IDE. Check Aleo’s GitHub for implementations for Visual Studio Code, Sublime Text, and IntelliJ.

Leo installation instruction you can find here as well:

Now, let’s run our token program.

Token program execution:

Navigate to the token directory and execute the provided bash script:

cd token
./run.sh

The .env file in this directory contains a private key and address. Adjust the private_key field in .env when executing programs as different parties.

Walkthrough: now, let’s embark on a step-by-step journey through the creation and transfer of our custom token.

Step 0: public mint. Let’s start by publicly minting 100 tokens as Alice. Swap in her private key and run the following command:

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp1w8PTxrRgGfAtfKUSq43iQyVbdQHfhGbiNPEg2LVSEXR
" > .env

leo run mint_public aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm3008q 100u64

This will finalize the minting publicly, and the information will be visible on-chain.

Step 1: private mint. Switch to Bob’s private key and privately mint 100 tokens for Bob:

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpFo72g7N9iFt3JzzeG8CqsS5doAiXyFvNCgk2oHvjRCzF
" > .env

leo run mint_private aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z 100u64

The output will be a private record.

Step 2: public transfer. Switch back to Alice and publicly transfer 10 tokens to Bob:

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp1w8PTxrRgGfAtfKUSq43iQyVbdQHfhGbiNPEg2LVSEXR
" > .env

leo run transfer_public aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z 10u64

This command displays the arguments for the finalize function of the public transfer.

Step 3: private transfer. Switch to Bob’s private key and privately transfer 20 tokens to Alice:

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpFo72g7N9iFt3JzzeG8CqsS5doAiXyFvNCgk2oHvjRCzF
" > .env

leo run transfer_private "{
owner: aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z.private,
amount: 100u64.private,
_nonce: 6586771265379155927089644749305420610382723873232320906747954786091923851913group.public
}" aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm3008q 20u64

The output will show records owned by Bob and Alice.

Step 4: public to private transfer

Switch back to Alice and convert 30 public tokens into 30 private tokens for Bob:

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp1w8PTxrRgGfAtfKUSq43iQyVbdQHfhGbiNPEg2LVSEXR
" > .env

leo run transfer_public_to_private aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z 30u64

This command modifies Alice’s public token mapping and creates a private record for Bob.

Step 5: private to public transfer. Switch back to Bob and convert 40 private tokens into 40 public tokens for Alice:

echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpFo72g7N9iFt3JzzeG8CqsS5doAiXyFvNCgk2oHvjRCzF
" > .env

leo run transfer_private_to_public "{
owner: aleo17vy26rpdhqx4598y5gp7nvaa9rk7tnvl6ufhvvf4calsrrqdaqyshdsf5z.private,
amount: 80u64.private,
_nonce: 1852830456042139988098466781381363679605019151318121788109768539956661608520group.public
}" aleo13ssze66adjjkt795z9u5wpq8h6kn0y2657726h4h3e3wfnez4vqsm3008q 40u64

This command modifies Bob’s private record and Alice’s public mapping.

And there you have it! You’ve successfully created and managed a transparent and shielded custom token using Aleo Leo. Feel free to explore further and unleash the full potential of decentralized finance. Happy coding! 🚀🔐

Video tutorial from team you can find also below:

To know more, join now!
Aleo Twitter
Aleo Discord
Aleo Website
List of Aleo and Leo code and resourses

Prepared by Colliseum

--

--