In this repository we will go through the steps to deploy your own Leo program on the Aleo Network.
Make sure you have the following software installed on your local machine:
If you run into issues while installing the above software, or following the workshop, please see the FAQ
You will need a Leo Wallet to deploy your program. You have two options to setup a wallet
You can create a wallet using the Leo CLI by running the following command
leo account new
Be sure to save the Address, View and Private Keys of this wallet, you will need them later.
Ensure you installed Leo Wallet and follow the setup process to create a new wallet.
You can get testnet tokens by using the Aleo Faucet.
If you are using the Leo Wallet Chrome Extension, you can also get testnet tokens by clicking on the wallet and then clicking on the Faucet
button. Scan the QR code and send the generated text message to recieve testnet tokens.
Run the following command to initalize a leo project. In Leo, programs must be unique, so make sure to use a unique name.
macOS & Unix based systems
leo new token_$RANDOM
Windows (choose a random string of alphanumeric characters)
leo new token_(RANDOM_CHARACTERS_HERE)
The result will be a new folder project_name
with the following structure:
.
├── README.md
├── build
│ ├── main.aleo
│ └── program.json
├── inputs
│ └── deploy_workshop.in
├── program.json
└── src
└── main.leo
Write your code in the src/main.leo
file. For this demo we will be using the following code that implements a basic token.
// Replace <project_name> with the name of your project.
program <project_name>.aleo {
// Define a token struct with an owner and balance
record Token {
owner: address,
balance: u32,
}
// Define a mint transition that takes a balance and returns a token
transition mint(amount: u32) -> Token {
return Token {
owner: self.caller,
balance: amount,
};
}
// Define a transfer transition that takes a receiver, amount and token and returns two tokens
transition transfer(receiver: address, transfer_amount: u32, input: Token) -> (Token, Token) {
let sender_balance: u32 = input.balance - transfer_amount;
let recipient: Token = Token {
owner: receiver,
balance: transfer_amount,
};
let sender: Token = Token {
owner: self.caller,
balance: sender_balance
};
return (recipient, sender);
}
}
In the ./inputs/project_name.in
file, we need to define the inputs for our program. For this demo we will be using the following inputs:
// The program input for deploy_workshop/src/main.leo
[mint]
balance: u32 = 100u32;
[transfer]
receiver: address = aleo1yn6halw6astkc8jsl88sukelef3e8xrawugfjtx7kjcuuxdm6spsdtc249;
amount: u32 = 10u32;
input: Token = Token {
owner: aleo102nryeeun6da4atqggu0q9aj5cqem7tpjzvce4nc88yzu29n8sgs9qelp7,
balance: 100u32,
_nonce: 661901642905281065575358583071347542160248627750537954509114007526888699661group
};
Let's make sure that our program is working by running the following commands:
- Does it build?
leo build
Leo ✅ Compiled 'main.leo' into Aleo instructions
- Can we mint tokens?
leo run mint
You should see the following output:
{
owner: aleo102nryeeun6da4atqggu0q9aj5cqem7tpjzvce4nc88yzu29n8sgs9qelp7.private,
balance: 100u32.private,
_nonce: 292936196563333932009136915121914006898609101920119023221288671394356999564group.public
}
Copy the output record from the mint transition and paste it into the ./inputs/project_name.in
file under the [transfer]
section. Be sure to remove the .private
and .public
suffixes.
- Can we transfer tokens?
leo run transfer
Leo ✅ Compiled 'main.leo' into Aleo instructions
⛓ Constraints
• 'deploy_workshop.aleo/transfer' - 4,075 constraints (called 1 time)
➡️ Outputs
• {
owner: aleo1yn6halw6astkc8jsl88sukelef3e8xrawugfjtx7kjcuuxdm6spsdtc249.private,
balance: 10u32.private,
_nonce: 3050046340461200467640466967043652446168052649619713936697821365575779437863group.public
}
• {
owner: aleo102nryeeun6da4atqggu0q9aj5cqem7tpjzvce4nc88yzu29n8sgs9qelp7.private,
balance: 90u32.private,
_nonce: 7955845234401838954345597221810328519950488237684582098690500295625246536712group.public
}
You can see here, one account now has 90 tokens and the other has 10, meaning we succesfully transfered 10 tokens.
We need a few environment variables set to deploy our program. We can create a script to set these variables for us.
Create a new file named deploy.sh
in the project directory and copy the following into the file
PRIVATEKEY=""
APPNAME="<project_name>"
cd .. && snarkos developer deploy "${APPNAME}.aleo" --private-key "${PRIVATEKEY}" --query "https://vm.aleo.org/api" --path "./${APPNAME}/build/" --broadcast "https://vm.aleo.org/api/testnet3/transaction/broadcast" --fee 1000000
Fill out the variables with the appropriate values and save the file
Run the deploy script
bash ./deploy.sh
You see output like this if successful
Don't forget to save your work!

