Write your very first crypto-token in solidity

Write your very first crypto-token in solidity

Sneha Maurya's photo
Sneha Maurya
·Feb 23, 2022·

4 min read

Table of contents

  • Prerequisites
  • Let's write your first cryptocurrency

gm! folks, As part of my web3.0 journey I'm learning solidity and ERC20 token, and to understand more the functionality here I'm building a smart contract that will mint cryptocurrency tokens. For learning purposes, we will be creating this contract together and deploying it on the test net. Why wait any longer, let's mint!

Prerequisites

Remix IDE

Well, we are using Remix IDE for writing our first cryptocurrency token code in solidity. If you are interested in knowing in more depth, what is remix? then check out its official document. For this blog scope, you must know Remix-IDE is an open-source web and desktop application. It is a powerful tool used to write, compile, deploy and debug Solidity smart contracts code on the Ethereum blockchain network. Yes, you heard me right you can deploy your contract on the test net as well as on Mainnet. If your Metamask wallet is injected into your chrome/browser then you can choose which environment by selecting Injected Web3 in remix while deploying your contract.

Screenshot 2022-02-06 233803.png

that for now Remix. move to our next prerequisite.

Solidity

We will be creating our cryptocurrency token contract using solidity. If you are new to solidity don't worry I gotta back. I had dropped a beginner blog on solidity, check this out. blog

Metamask

If you haven't installed Metamask in your browser, go ahead and install it, I'll wait here. Metamask Metamask setup blog

Faucet eth

What? (yup! you got it we need a faucet eth for paying the gas fee) some resources from where you can request some faucet eth.

Let's write your first cryptocurrency

Before we jump on writing solidity code for our cryptocurrency, have you ever wondered how all our Ethereum based cryptocurrencies are working, from minting to sending your friend's crypto wallet? You must be. So, let's see. We are going to use the ERC-20 token in our contract for minting cryptocurrency token and seeing it in our wallet till sending it to our friend's wallets. Pretty amazing right. I'm pumped up !!.

ERC -20: ERC stands for Ethereum Request for Comment. Everything in Ethereum is just a smart contract, and there are no rules about what smart contracts have to do, the community has developed a variety of standards (called EIPs or ERCs) for documenting how a contract can interoperate with other contracts and convey technical requirements and specifications for certain use cases.

ERC-20 is token standard from OpenZeppelin. It keeps track and outlines the technical specification of fungible token which is used as currency, a medium of exchange, etc. A fungible token doesn't carry any specific feature from another similar fungible token, all are similar in their value unlike NFTs(non-fungible tokens). If you are curious to read more on the standards, go through OpenZeppelin ERC-20 docs.

Without any further due, let's write a very first cryptocurrency smart contract. Go ahead open your remix and write the below contract.

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

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

contract SamosaToken is ERC20{

    constructor(string memory _name,string memory _symbol) ERC20(_name,_symbol){
        _mint(msg.sender,10*10**18);  // _mint is internal function
    }
}

Once your contract is ready, let's compile it. I'm taking you already went through the remix doc to understand the platform.

  • Make sure you are on the Rinkeby test net in your metamask.

Now deploy your smart contract, and make sure you choose injected web3 option in the environment section. It is important to get your Metamask on work, yup this will allow remix to defer all the control for blockchain integration to your Metamask and now it controls which network you are connecting to. This way you will be paying the transaction gas fee with your wallet. Screenshot 2022-02-06 233803.png

Once the environment setup is done go ahead give your token a name and symbol and deploy.

Screenshot 2022-02-06 235605.png

Woohoo!! you successfully deployed your very first Cryptocurrency token smart contract on the test net.

Screenshot 2022-02-06 235652.png

Now you need to copy your smart contract address.

Screenshot 2022-02-06 235728.png

Go to your Metamask and make sure you are on the Rinkeby test net.

  • You will see the import token below in Assets part of your Metamask.
  • add your contract address, symbol, and name. Once you complete these steps you will be able to see your token like below.

Screenshot 2022-02-06 235758.png

Your very first cryptocurrency token is now in your wallet. Play as much as you want with your token. I have gotta send some Samosa (my cryptocurrency token name) to my friends !!

 
Share this