Categories
Flare Network Songbird Network

Securely mint a Songbird token using Remix

This post will walk you through how to create your own token on the Songbird canary network.

What will be covered?

This post will walk you through how to create your own token on the Songbird network. You will use a web-based integrated development environment (IDE) to deploy your token contract. So, you will not have to install anything on your local computer.

We will cover the following steps in this tutorial:

  • Walkthrough the Remix IDE
  • Create our token Solidity code file
  • Add Solidity code to create token contract
  • Add your custom token to MetaMask
  • Deploy token to the Songbird network
  • View our token on the Songbird explorer

Assumptions

You don’t need to be a seasoned developer or Solidity expert to go through this tutorial. I assume you have some experience coding and using IDEs or experience in some type of programming language. If you don’t have experience coding, you can still work through this guide. Deploying your own token to the Songbird canary network is only a few lines of code.

The last thing that is assumed is you have a Songbird wallet in MetaMask. If you have not set that up MetaMask, you can find another post here titled Creating a new Songbird wallet using MetaMask explaining exactly how to do that. You will need a Songbird wallet in MetaMask because you will deploy your token contract using that wallet, and all tokens initially minted will be sent to your Song wallet address.

Using the Remix Ethereum Web IDE

In this section, you will be introduced to Remix an Ethereum web-based IDE. To give a quick overview of what Remix is, it is essentially an in-browser IDE that allows you to write Solidity code for any EVM based blockchain. Since Songbird uses the EVM, you can write all smart contracts that run on Songbird and Flare using Solidity, the most popular smart contract programming language. The advantage you get from this is if you are coming from writing smart contracts on Ethereum or a side-chain like Polygon, all of your skills and development stack migrate over seamlessly.

To use Remix you will navigate to the following URL https://remix.ethereum.org/

Once you navigate to Remix, you will see the following screen.

Initial Remix IDE
Initial Remix IDE

Remix code clean up

Before we start, we will clean up the unneeded code files that are included when you initially navigate to Remix. In the navigation pane to the right, you will delete the following files:

Files to delete in the contracts folder:

  • 1_Storage.sol
  • 2_Owner.sol
  • 3_Ballet.sol

Files to delete in the tests folder:

  • 4_Ballot_test.sol
See files to delete
See files to delete

Once you have deleted the files that were not needed, your project workspace should look like the image below.

Remix project workspace after deleting files
Remix project workspace after deleting files

Next, in the contracts folder, create a file called MyToken.sol. Once you have created that file, your workspace should look like the image below.

MyToken.sol files has been added
MyToken.sol files has been added

Now that you have cleaned up your project workspace and added your file containing the code for your token, we will start coding. If your MyToken.sol file is not open, open it in the editor and copy the Token Code below and paste it into your file.

Token Code

Code to copy

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

//imports the needed openzeppelin ER20 contract
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

//the name of your token contract that inherits from the openzeppelin ER20 Contract
contract MyToken is ERC20 {
 
    /*
        the contract constructor accepts a parameter of "initialSupply" which 
        is the total number of tokens that will be minted.
    */
    constructor(uint256 initialSupply) ERC20("BlockchainDevs.io", "BCD") {
        
        /*
            calls the _mint method which is part of the 
            @openzeppelin/contracts/token/ERC20/ERC20.sol contract
            
            the two parameters passed to the _mint function are:
            the sender deploying the contract and the initial token supply
        */
        _mint(msg.sender, initialSupply);
    }
}

Code view in Remix editor

After adding the code to the Remix editor, your editor file should look like the screen capture below. You will also notice that other files were added to your workspace. These files were automatically imported into the workspace when you added the import statement for @openzeppelin. All the files that were added are needed when your token contract is compiled.

Token Solidity Code

Quick Code Explanation

I will give a brief explanation of the code above based on the line number in the Remix IDE.

Line 2 – The pragma statement lets the compiler know which version of Solidity you are using.

Line 5 – Imports the openzeppelin ERC20 contract. The openzeppelin ERC20 contract has passed security audits and is the recommended library when building ERC20 tokens.

Line 8 – Declares your contract name and inherits the openzeppelin ERC20 contract. Notes – Where you see BlochchainDevs.io, you will replace it with the name of your token, and where you see BCD you will replace it with your token symbol.

Line 23 – Calls the _mint function, which will send the initial token distribution to your Songbird wallet address in the amount of the initial supply.

After you have added the code, you will need to compile the contract to be deployed to the Songbird blockchain.

Compiling Songbird Token contract (MyToken.sol)

To compile your contract, you will need to click the Solidity icon in the left-hand pane to navigate to the Solidity compiler. See the image below.

Solidity Compiler
Solidity Compiler

Solidity Compiler settings

Next, you will need to ensure that all the correct settings have been selected so that no errors occur during compilation. Below, the step has been numbered based on the order of the steps that should be taken.

  1. You should first set the Solidity compiler to use 0.8.7+. This is what was set in the MyToken.sol. Settings the compiler to use another version will create an error and keep your contract from compiling.
  2. Set the Contract section to the MyToken.sol file. This is probably set to the ERC20.sol when you initially navigate to this screen. If you don’t set this to MyToken.sol, the contract will not be compiled.
  3. After you have your settings correct, you can click the Compile MyToken.sol button.
  4. If your contract compiles successfully, you will have a green check next to the Solidity icon, as seen in the image below.

See the screen capture below for the correct settings.

Solidity Compiler settings
Solidity Compiler settings

Deploying your token to the Songbird blockchain

To mint your token on the Songbird network, you will need to navigate to the deployment pane. You can navigate to the deployment section by clicking the Ethereum icon in the left pane. See the image below.by clicking the Ethereum icon in the left pane. See the image below.

After you have navigated to the deployment section, you will see the screen below.

Contract deployment section
Contract deployment section

We will need to make several changes to deploy your token to the live Songbird blockchain. Before you change this setting, you will need to ensure MetaMask is set to your Songbird wallet. If you have not created a MetaMask Songbird wallet, you can follow the steps outlined in a previous post here Creating a new Songbird wallet using MetaMask. See the image below of my Songbird wallet in MetaMask that will be used to mint my token on the Songbird blockchain.

Note – You will not be able to do any other steps in the tutorial if you don’t have a Songbird wallet linked to MetaMask.

Songbird wallet that will be used to deploy token contract
Songbird wallet that will be used to deploy token contract

Changing Environment setting

The Environment setting is currently set to a local in-browser Ethereum blockchain clone, which is not what we want. You will now change the Environment setting to Injected Web3. See the image below for the Environment option you should select.

Selecting Injected Web3
Selecting Injected Web3

Finalizing Deployment Settings

Next, I will outline what the remainder of the settings should be set to.

Final Deployment settings
Deployment Settings explanation

Refer to the Final Deployment settings image above.

The item mark as #1 in the screen capture is what you should see after changing your Environment setting to Inject Web3. Note that you see Custom(19) networkCustom(19) network represents the Songbird Chain ID which is 19..

The item marked as #2 in the screen capture is the Songbird account auto-populated from MetaMask. If you recall, my Songbird wallet had one Songbird token in it. Ignore the word ether; since we interact with an EVM-based blockchain, Remix will always refer to your balance as ether.

The item mark as #3 in the screen capture, you will select MyToken. Having the MyToken select will ensure that your token contract is deployed to the Songbird blockchain.

The item mark as #4 in the screen capture references the input field where you will enter your total supply of tokens that will be minted. 

For example, the total tokens I am minting is 21,000,000. Therefore, in the field, I have actually entered 21000000000000000000000000 in the initial supply. 

The reason I am using 21000000000000000000000000 and not 21,000,000 is how the EVM handles numbers. There are no floating-point numbers in the Solidity programming language. When you mint a token, you are actually sending it in a unit called Wei. I won’t bore you with the details, but you can find a simple converter here that will allow you to convert Ether to Wei. So, my initial supply is being deployed as 21000000000000000000000000 Wei. 

Since I want to mint 21 million of my token, you can think of me entering 21,000,000 and then 18 zeros after it since most ER20 tokens use 18 decimal places.

After you have entered your desired initial supply, you can click the Deploy button marked #5.

Confirming Contract Deployment

Once you click Deploy, MetaMask should prompt you to confirm the transaction with your Songbird MetaMask wallet. See the image below.

Contract Deployment confirmation
Contract Deployment confirmation

You can see the estimated gas fee and the total that it will cost you to confirm the deployment of your token contract. Remember to have enough Songbird in your MetaMask wallet to confirm the transaction, or it will fail. So, to deploy this token contract, it will cost me 0.280287 SGB tokens or roughly $0.125 at the time of writing this. After reviewing the transaction, you will then click the Confirm button.

Successful deployment of Songbird token contract

Below you can see an example of what MetaMask looks like after successfully minting a new token.

Remix after deploying token contract

After you have successfully deployed your token to Songbird from Remix, you should see a screen similar to the one below.

Remix successfully deployed token contract
Remix successfully deployed token contract

The item marked #1 is the contract address identifying your token on the Songbird blockchain in the image above. Item marked #2 allows you to copy your contract address where your token contract resides.

Congrats, you have now officially minted your token on the Songbird network. Now you are probably wondering how you have those tokens show up in your MetaMask wallet. We will walk through those steps next.

Importing your new Token into MetaMask

In the previous section, I mentioned you could copy the contract address from Remix after it was deployed. If you have not copied your token contract address, do so now. You will next use the contract token address and add it to your MetaMask wallet.

The token info for the token that I minted is below:

Token Name: BlockchainDevs.io

Token Symbol: BCD

Contract Address: 0x9Eb3E3a6f2D35da20AC257c8087c3BdD5F6be936

Now that I have the contract address, I can import it into MetaMask.

To add the token, you will open MetaMask in your browser. Once you have MetaMask open, you will click the Import tokens link at the bottom of the screen. See the image below.

Importing a token to MetaMask

Now click the Import tokens link, and you will see the screen that is pictured below.

You will then input the Token Contract Address that was generated when you deployed your token contract to the Songbird blockchain. See the image below for an example of the token that I created.

Contract token information populated

Once you add your token contract address, the Token Symbol and Token Decimal should auto-populate since this information will be pulled from the contract. The information displayed on your screen will be dictated by what you named your token and the symbol you gave your token. Next, you will click the Add Custom Token button. After you have added the custom token, the following screen will display. Your screen will have your token information.

Import Tokens confirmation screen

After you have verified you are importing the correct token, you can click the Import Tokens button. After importing the custom token, the tokens will be added to your MetaMask wallet. You will then see a screen showing your token and the number of tokens you minted during the deployment of your token contract.

New custom token

Next, navigate back to the MetaMask home screen by clicking the arrow in the upper left-hand corner of your wallet. You should then see your new token in your Assets list. You can see an example of this below after I added my new custom token. I now have 21,000,000 BCD tokens which was the symbol given to the token when I created it.

New Token added to Assets

You have officially minted your own token on the Songbird canary network. You can now send your tokens to whoever you would like to. You simply select your token and send it like you would send any other token using MetaMask. For your tokens to show up in MetaMask for those you send them to, they will need to add your custom token address to MetaMask. It will then show the number of your tokens that were sent to them. They would need to follow the steps outlined in this post section – Importing your new Token into MetaMask.

View your token on the Songbird network

We will now briefly walk through how to view your new token on the blockchain using the Songbird Explorer. To view your token using the Songbird Explorer, you will need to navigate to the following link. Once you navigate to the Songbird Explorer, you will see a screen similar to the one below.

Songbird Token Explorer
Songbird token explorer

Next, type in your token name or the symbol you gave to your token in the search box highlighted in the image above. Since I gave my token

Token search results

The search results show the name of my token, the token contract address, the total supply that was minted, and the current number of holders of my token. Remember, the wallet that deploys the initial token contract receives all the initial total token supply.

If you click on the name of your token in the search results, it will show you the token transfers of your token on the Songbird blockchain. Currently, the only token transfers are when my tokens were minted and sent to my wallet. See the image below.

Token transfers

You can also see a list of all the current holders of your token. If you click the Token Holders tab, it will display all the addresses that hold your token, the percentage they hold, and the total number of tokens the address has. See the example in the image below.

Token holders

As I send others tokens, the list of token holders will grow. As a reward for getting this far in the blog post, send a message on the contact us page and your ETH-based address, and I will send you some BCD tokens as a novelty :).

Summary

In this post, we covered a range of topics starting with using the Remix browser-based IDE. Next, you created a new Solidity file and added Solidity code to create your token contract. You then compiled the contract and deployed it to the Songbird canary network. Once the token contract was deployed, we added the custom token to MetaMask. Finally, you were able to view your new custom token on the blockchain using the Songbird Explorer.

I hope you found this post both educational and informative. Feel free to let me know if anything is unclear or needs clarification, and reach out anytime if you have questions.

Leave a Reply

Your email address will not be published. Required fields are marked *