Breaking down the Aleo example: Simple Token

Kaylej
2 min readMar 20, 2023

--

In this article, we’ll look at how a simple token on the Aleo blockchain works. Let’s see how the code looks like in the Leo language, as well as analyze the differences from Solidity.

First we’ll assemble the contract constructor:

record — is the token template. Here we record the owner to whom we mint all the tokens, gates (which is almost always zero by default, this is not present in Solidity, but we can ignore it), and amount (the number of tokens). We refer to this template next:

This is a function that is purely external. That is, it’s a roughly speaking interface, inside of which nothing happens. Here we just create a token with input values.

Then comes the biggest function denoting the transfer of funds:

Here, difference — is the amount of money that remains with the owner after transferring funds to someone.

If we use an analogy with Solidity, it is followed by afterTransfer (i.e. updating balances, but without checks):

In remaining we write the data for the sender: here only the number of tokens changes, and it has decreased.

In transferred we update the token ownership data for the recipient.

Right away we pay attention to inputs:

It is worth noting that this is a demo for the token contract and there are no checks and allowances; this means that basically any user can do a transfer here from anyone to anyone.

Also here we can perform the mint function as many times as we want, creating clone tokens.

Test this contract yourself at https://play.leo-lang.org/ !

Original version: https://medium.com/@kaylej/e524a4894f4c

--

--