How To Build Your Own Cryptocurrency

Ashutosh Agarwal
4 min readAug 1, 2021

First Cryptocurrency Bitcoin was introduced in 2009 and it has been around for more than 10 years now. But just recently only people have started taking more interest in it. The reason being the benefits and easiness with which one can create their own currency.

I have divided this into three sections. Feel free to skip anyone.

  1. Overview
  2. Let’s Build One
  3. What to do next

https://github.com/ashutoshag01/cryptoCurrency

Overview

Cryptocurrency is a digital currency that doesn’t need any central authorities like banks for regulation. It works in a fully distributed system where anyone in the network can make a peer-to-peer transaction. Where our traditional transaction goes via banks and then the money is transferred to the recipient, in case of cryptocurrency amount is directly sent to the recipient. As this system is fully distributed and there is no central authority, so users have more anonymity, privacy, versatility, less corruption, and lots of other benefits.

The absence of central authority doesn’t mean transactions aren’t going to be verified. Validation of transactions to avoid frauds, double-spending, etc. are done by the group of distributed node who are called miners. Miners do some Proof-Of-Work to verify the transactions and encrypt them so once the transaction is committed it can’t be reversed. Miners verify a set of transactions, merge them into a single block, and add it to the existing blockchain. And for all these works, miners are rewarded with some incentives.

If you need more insights on its working you can watch this video https://www.youtube.com/watch?v=bBC-nXj3Ng4&t=1055s

Let’s Build One

Create Smart Contract

Now we know something about Cryptocurrency what are and why they are getting popular so let’s get our hands dirty then. Cryptocurrency is built by creating ERC-20 token using smart contracts. Which is analogous to the java class. Having methods and variables for interaction but one catch is, once deployed it can’t be changed. Contract address is made publicly available using which users call functions to send or receive token. You can click here to see one such publicly available contract.

For building it, I have used Ethereum online EVM https://remix.ethereum.org/ for compiling and deploying Smart Contract. Ethereum supports contracts in 2 languages Solidarity and Yul. Here I have used Solidarity for creating it. You can check the code from the mentioned Github Link Repo.

My Contract contains below

Variables: For storing information.

symbol -> Symbol for the token
name -> Name of the token
decimals -> Total place of decimals token supports
_totalSupply -> Total number of token available
owner -> Person who owns the contract
balances -> Map to store number of token corresponding to adress
allowed -> Map to track if transaction is allowed;

Functions: methods for interacting with smart contracts. Below are all the methods I have implemented in it.

totalSupply() -> to get the total supply of tokens
balanceOf() ->balance of the account passed
allowance() -> check allowance for the user
transfer()->transfer tokens to an address
approve() -> approves the transaction
transferFrom() -> send tokens from one address to another

Events: As our system is fully distributed events are the way to broadcast updates regarding the transaction to everyone in the network. There are 2 events I have created in the smart contract

Transfer() =>Whenever a transaction is made
Approval() => Whenever a transaction is approved

Now choose the SOLIDITY COMPILER option from the left navigation and compile your code.

Deploy

Deployment is done using the option DEPLOY & RUN TRANSACTIONS from the left nav. But when deploying you’ll get 3 options.
1. VM
2. Injected Web3
3. Web3 Provider

Deployment done in VM is temporary as it stores the data in local machine and when the page is refreshed everything is gone. To make it accessible outside local machine we’ll use Injected Web3.

For this, we need MetaMak which is a browser extension for the cryptocurrency wallet. Download the extension, create the account and select the Rospten Test Network. Now when deploying using Injected Web3, it will open the MetaMask wallet for the transaction and it will ask to pay some gas to make your contract available on TestNet. Don’t worry you don’t have to pay from your pocket. One can easily get gas, Ethers in case of Ethereum, online and if you are having trouble getting some let me know I’ll transfer some to you.

And done... You are all set. Congrats!!. You’ll able to see tokens in your wallet which you can send to anyone using theirs public address.

What to do next

Now you have your own cryptocurrency and you are able to send it to your peers but what’s next. It is not just limited to building one. This will open up lots of possibilities for you.
1. Integrate it with your website to start accepting your own currency as payment. If you need APIs for doing that check the GitHub link.
2. Make your website or app Web3 compatible.
3. Look for underlying working, blockchain, mining, and many more.

If you find this post useful, please tap 👏 the button below :).

--

--