How to Create your Own Cryptocurrency - Testnet Token

How to Create your Own Cryptocurrency - Testnet Token

Ayodele Samuel Adebayo
·Jun 15, 2022·

10 min read

Play this article

Table of contents

Cryptocurrency is a new way of exchanging value, rewarding users, and paying for what you purchased. It’s often seen as the digital version of money on the internet.

According to Wikipedia: “A cryptocurrency is a tradable digital asset or digital form of money that is built on blockchain technology and only exists online.”

This tutorial will guide you on how to create and deploy your own cryptocurrency on the Rinkeby Testnet blockchain, which is transferable to other crypto wallet addresses.

Prerequisites

Before you continue with this tutorial, you should:

  • Have Metamask installed.
  • Have a basic knowledge of the Remix IDE.
  • Have a basic understanding of Solidity smart contract, which you can find here.

What Are Some Reasons to Create Your Own Cryptocurrency?

  • Testing purpose during dApp development.
  • Rewarding your users.
  • Membership coin.
  • In-game currency.
  • Fun currency owned by you and your friends.

    In this tutorial, we’ll create a fun cryptocurrency that we can share with our friends for either completing a task or winning a bet.

Step 1 - Writing the Smart Contract

The first step is to write a smart contract that will handle our cryptocurrency functionalities.

You can name your cryptocurrency whatever you want, but for this tutorial, we'll name our cryptocurrency "UncleBigBay and Friends Token" with a symbol of "UBBFT".

  • Launch the Remix IDE by clicking here:

    Remix IDE is used for the entire journey of contract development with Solidity language as well as a playground for learning and teaching Ethereum.

  • In the contracts folder, create a new .sol file with the name of your currency, like this: UncleBigBay_and_Friends_Token.sol.

    creating a new Solidity source file for writing a test token on the Remix IDE

  • Copy and paste the following smart contract inside of your .sol file:

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

// Token Smart Contract
contract UncleBigBay_and_Friends_Token {

    // 1. Token balance for address
    mapping (address => uint) public balances;

    // 2. Authorized amount allowed for others to spend
    mapping (address => mapping (address => uint)) public allowance;

    // 3. Token name
    string public name = "UncleBigBay and Friends Token";

    // 4. Token Symbol
    string public symbol = "UBBFT";

    // 5. Token Decimals
    uint public decimals = 18;

    // 6. Initial Supply
    uint public tokensIActuallyWant = 9000000;
    uint public totalTokenSupply = tokensIActuallyWant * 10 ** decimals;


    // 7. Assign the total supply to the owner
    constructor(){
        balances[msg.sender] = totalTokenSupply;
    }

    // 8. Get balance of token owners
    function balanceOf(address owner) public view returns (uint){
        return balances[owner];
    }

    // 9. Transfer and Approval event
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);


    // 10. 2 party transfer token from one wallet to another wallet address
    function transfer(address to, uint value) public returns(bool){

        // If transfer value is lower than the balance in the wallet
        require (balanceOf(msg.sender) >= value, 'Your balance is too low');

        // Increase the balance of the receiver
        balances[to] = balances[to] + value;

        // Deduct the balance of the sender
        balances[msg.sender] =  balances[msg.sender] - value;

        // Call the transfer function
        emit Transfer(msg.sender, to, value);

        // exit
        return true;
    }


    // 11. 3 party transfer token from one address to another address (requires approval)
    function transferFrom(address from, address to, uint value) public returns(bool){

        // If transfer value is lower than the balance in the wallet
        require(balanceOf(from) >= value, 'Your balance is too low');

        // If the transfer amount is higher than the authorized allowance
        require(allowance[from][msg.sender] >= value, 'You can not spend up to this amount');

        // Increase the balance of the receiver
        balances[to] += value;

        // Deduct the balance of the sender
        balances[from] -= value;

         // Call the transfer function
        emit Transfer(from, to, value);

        // exit
        return true;
    }


    // 12. Function to approve token transactions
    function approve(address spender, uint value) public returns(bool){
        // Check the authorized allowance of the spender
        allowance[msg.sender][spender] = value; 

        // Approve the transaction if they don't exceed their allowance
        emit Approval(msg.sender, spender, value);

        // exit
        return true;
    }   
}

In our smart contract above,, we're creating a total supply of 9 million UBBFT tokens with the following functions:

  1. The transfer() function enables our token holders to transfer from their wallets to other wallet addresses.

  2. The transferFrom() function enables approval of token transactions, using the allowance mechanism, so that the spender doesn’t spend more than their token limits. It also allows our token holders to spend tokens on our behalf, for a gas fee or transaction confirmation on the blockchain.

  3. The approve() function authorizes the transferFrom() transaction if the spender hasn’t reached its limit.

The transfer of tokens between wallet addresses is known as the Transfer event, while the authorization of token transactions is known as the Approval event.

Step 2 - Compiling the Smart Contract

In this step, we're going to compile our token smart contract using the Remix IDE compiler.

Follow the steps below to compile your smart contract:

  • Save your source file with ctrl + s.

  • Navigate to the "Solidity Compiler" tab:

    compiling Solidity smart contract for creating your own cryptocurrency on Remix IDE

  • Select the "Compiler" version of your smart contract:

    configuring the Remix IDE compiler to run the same version with our Solidity smart contract

  • Click on the "Compile" button:

the compile button on the Remix IDE will check for errors in our smart contract

If the "Solidity Compiler" green check turns to red, select the same smart contract version in the "Compiler" tab.

Step 3 - Getting a Rinkeby Testnet Token

In this step, we're going to deploy our smart contract on the Rinkeby Testnet. We also need some Rinkeby Testnet tokens in our wallet to pay for the smart contract deployment gas fee.

We’ll use FaucETH, a website in which you can transfer some free fake ether to your wallet.

Make sure to have Metamask installed on your browser or install it here before you proceed.

fauceth provides free Ether for testing smart contracts in the Testnet before deploying to the Mainnet blockchain

  • Next, click on your Metamask icon, make sure to select the "Rinkeby Test Network", and copy your wallet address.

Viewing Metamask wallet address and switching to Rinkeby Network

  • Next, paste your wallet address inside of the input box, as shown below:

fauceth required your wallet address before requesting for free Rinkeby fund

  • Select the Rinkeby option, solve the captcha, and click on the "Request Fund" button to process your free ETH:

Providing the wallet address and solving captcha on the fauceth website

Wait for the page to process your request (this could take a few minutes):

fauceth processing requested Rinkeby fund

If the requested fund is successful, you'll be notified, as shown below:

Success modal showing successful message

Next, check your Metamask wallet. Your wallet should be credited with 0.45ETH, like this:

Metamask wallet credited with free Testnet Eth

Note: You can only request free ether every 60 minutes.

Step 4 - Deploying the Smart Contract

After compiling our smart contract (see Step 2) and funding your wallet with a fake ETH token, the next thing to do is to deploy the smart contract on the Rinkeby Ethereum blockchain.

Rinkeby is an Ethereum Testnet network that’s used to test blockchain development before deploying on the Mainnet network.

You can deploy your smart contract on any Testnet blockchain of your choice, just make sure to have the token to pay for the gas fee.

Deploying on the Mainnet blockchain will require real money for the deployment gas fee.

Follow the steps below to deploy your smart contract on the Rinkeby Ethereum blockchain:

  • In Metamask, switch from the Mainnet to the Rinkeby network:

    MetaMask is a software cryptocurrency wallet used to interact with the Ethereum blockchain. It allows users to access their Ethereum wallet balance

  • Click on the "Deploy & Run Transaction" icon in the Remix sidebar.

  • Select "Injected Web3" as the environment.

  • Choose your smart contract name in the "Contract" section.

  • Leave the other default options as they are, and click on the "Deploy" button: deploying a cryptocurrency token smart contract on the Rinkeby Testnet

  • The "Deploy" button will trigger Metamask. From your Metamask pop-up dialog box, click on the "Confirm" button:

    paying for Rinkeby Testnet gas fee on the Metamask for deploying a smart contract

  • Next, wait for the smart contract to deploy:

    waiting for block confirmation on smart contract deployment

  • When your smart contract is deployed, you’ll receive a notification in your Remix IDE terminal, as shown below and you’ll be able to access your smart contract address under the "Deployed Contracts" section:

    smart contract deployment notification on the blockchain will be shown on the Remix IDE

Step 5 - Importing Our Token in Metamask

In this step, we're going to import our deployed token into our Metamask wallet.

  • Copy your token smart contract address:

    after deploying smart contracts, their addresses are needed to interact with the contract functions

  • On your Metamask, switch to the deployed network, which in this case is the “Rinkeby Test Network”.the dep

    your Metamask must be on the deployed network

  • Click on "Import Tokens" on your Metamask wallet: importing our deployed custom token on Metmask wallet

  • Paste your smart contract address in the input box, “Token Contract Address”..

  • Your token symbol and decimal will be displayed automatically, as shown below.

  • Click on the "Add Custom Token" button:

    importing our deployed custom token on Metmask wallet

  • Confirm to import the token in your wallet. Out smart contract’s initial supply will be displayed as well:

    confirming importing our deployed custom token on Metmask wallet

  • After the confirmation, our token will be added to our wallet:

    confirming importing our deployed custom token on Metmask wallet

Step 6 - Sending Our Token to Others

In this step, we're going to transfer some of our tokens to another wallet address.

Follow the steps below to send your cryptocurrency token to another wallet address:

  • Request the receiver's wallet address:

    Requesting for the user's wallet address

  • Ask the receiver to import the token on their "Rinkeby Test Network" in their Metamask: importing our deployed custom token on Metmask wallet

  • Share your smart contract address with them and follow Step 5.

  • Next, click on your token under "Assets":

    view your token by clicking the assets tab

  • Click on the "Send" icon:

    the icon button on Metamask is used to send tokens to another address

  • Enter the receiver's wallet address and click the "Next" button:

    The receiver's wallet is required to send the token to the receiver

  • Enter the amount you want to send:

    Enter the amount to send to the wallet

  • Confirm the transaction:

    confirming the transfer transaction

  • Wait for the transaction to be processed and confirmed on the blockchain:

    waiting for the block to confirm the transaction

  • You'll be notified whether or not the transaction was successful: Metamask will display the transaction status of transferring tokens to another wallet

  • Confirm with the receiver if they've received the fund:

    if the Metamask shows send status, the receiver should receive the token in their wallet

  • Check your token balance and transactions:

    Checking your token balance and transaction on Metamask wallet

Wrapping Up

In this tutorial, we've learned how to create and deploy our own cryptocurrency token.This token can also be transferred from one wallet address to another.

This tutorial deploys our token on the Testnet environments, although you can apply the same steps when you're ready to deploy to a Mainnet network (requires real money for the gas fees).

Where Do You Go Next?

Now that you’ve learned how to create and deploy your own cryptocurrency, and how to distribute it to another wallet addresses:

  • Learn How to Build a Web3 Login with Web3.js Library here.

  • Learn How to Build your Own NFT Explorer with Moralis React SDK here

  • Learn How to Build and Deploy an NFT Minting dApp with Solidity and React here


This article is a part of the Hashnode Web3 blog, where a team of curated writers are bringing out new resources to help you discover the universe of web3. Check us out for more on NFTs, DAOs, blockchains, and the decentralized future.

 
Share this