It is important to understand the different types of tokens which can be traded or sold on a blockchain like Celo. There are many use cases for blockchain tokens, and developers are coming up with new ones all the time. This tutorial will show you how to create your own fungible token on Celo using the Solidity smart contract language.
- Celo environment setup for Remix, tutorial for which can be found here
- Basic knowledge of Solidity and the Remix IDE
Tokens are a unit of measurement, some of which can be used in the virtual world. A token can represent any value the creator wants it to have. Some examples:
- Shares of a company
- Player currency in online games
- A unit of influence in governance of DeFi projects
- A piece of art or media
Broadly these digital tokens can be classified into two categories:
Fungibility means replaceable by another identical item. In simple terms, tokens that have equal value and are interchangable. This could be understood in much the same way as fiat currency - a dollar bill of a certain denomination. Every dollar is equal to every other dollar of the same value, except in very specific circumstances any five dollar bill could be replaced with any other five dollar bill. The exact value of a cryptocurrency token could be subject to change, but one fungible token could serve all the same functions as any other fungible token issued by the same on-chain contract.
As you can guess, these are exactly the opposite of fungible tokens: They are not replaceable. Every non-fungible token is unique, thus cannot be interchanged. Examples can be digital art or songs.
In this example we will learn how to mint fungible tokens. We will use a standard interface of fungible tokens that is quite popular on the Ethereum blockchain and learn how to build similar tokens on Celo.
ERC-20 is a standard interface used on Ethereum to build fungible tokens. The "ERC" portion of the name refers to "Ethereum Request for Comments" and is a standard adopted by the Ethereum foundation as well as many projects which develop predominantly on Ethereum.
Because the Solidity language can be used by any EVM-compatible blockchain, the entire standard can be reproduced on Celo with little extra work.
This interface contains some functions:
As well as some events:
These need to be defined before deploying our smart contract on the blockchain.
In this tutorial, we will create a minimalistic version of ERC-20 (fungible) tokens.
We have named our contract
CeloFungibleTokenand the implementation is given below. Create a new file on Remix named
erc20.soland copy the code below:
Our contract should be able to compile now.
We will deploy our contract on Celo's Alfajores testnet. We need to make sure that we have enough balance in our testnet account. We can get free testnet balance from the Celo Developers faucet.
a. Select the account on Celo Wallet with which we want to deploy the smart contract. Make sure to select the account on Alfajores testnet!
c. Pay the
transaction feeand sign the transaction using celo wallet.
Congratulations! we have deployed our very own Fungible token on the Celo blockchain. It usually takes around 5 seconds to achieve finality for our transactions. Once our transaction is confirmed, let's head over to BlockScout to see all the details.
Here are the details of the smart contract deployment shown in this example.
Now that our contract is deployed, we have all the CFT tokens that exist on Celo Blockchain. There are many ways of transferring tokens from one address to another. We will discuss a couple of methods.
1. SMART CONTRACT INTERACTION :
a. Select the account which has 1000 CFT, in the example case
0x0eAd666A5B65ED614990fD582693039ed49847E6(which you can verify on Blockscout using the link given above) on Celo extension wallet.
b. In the transfer tab and we need to enter the Alfajores Testnet Address of the account to which we want to transfer the tokens with the amount of tokens to be transferred. For this tutorial, we will use
0x39E526B01fDe70d64FABDCe5Ca92b47789AA231Dand send 10 CFT tokens (be mindful of decimals that we defined in the contract).
c. Click on
d. Pay the
With that, we have learned how to transfer your fungible tokens to other addresses. But there is still a problem, we aren't able to see our tokens on our Celo wallet. To display the tokens we'll need to:
- Select the Add Token button on our Celo wallet as shown in the image.
- Enter the contract address in Token Contract Address and click
- Click on
Now we are able to see our token balance!
2. Celo Wallet
After adding the token address to our wallet, simply click on the Send button and input the address of a recipient. Tokens will be transferred after signing the transaction and paying the transaction fee.
In this tutorial, we learned:
- Some different use cases of fungible tokens
- There are different types of tokens with different standards
- How to deploy a custom fungible token on the Celo blockchain
- How to send tokens over Celo!
We cannot wait to see what you create!