Any Moron Can Make Crypto
I've meddled with cryptocurrencies in the past.
I've owned quite a few coins myself over the last few years, and even had about $200 worth of BNB in May 2021.
That was before Elon Musk's tweet about the dangers of bitcoin's carbon footprint and the subsequent crash of the crypto market.
I got broke over time, sold some of my holdings and the market dip decimated the rest. And now I have a measly $25 account balance that I just stare at sometimes when the mood strikes.
I knew a lot about blockchains and cryptocurrencies before I started learning about them officially in August 2022. I even write crypto-related articles for a mini blog as a side hustle.
However, a project I was building has presented me with a chance to do something very exciting after two months down the blockchain rabbit hole.
Why Am I Writing This Article?
Over the last month, I've compiled some blockchain-related projects into a personal portfolio. One I can present to potential employers as proof of my skills, and hopefully get a job as a blockchain developer.
So far, I've built a blockchain hotel rental app, an NFT marketplace and an NFT-related game. However, the project I'm working on now is a mini crypto exchange (no disrespect to CZ) called GelatoSwap. For GelatoSwap, I plan to create a native cryptocurrency (called GelaToken) the app's users can exchange for a dummy version of Ether.
Pretty basic stuff, but the idea is simple: I get to create my very own ERC-20 cryptocurrency and implement some of the things I've learned about how crypto exchanges actually work.
As part of my portfolio, I've included a section to contain some of the blog posts I've written, and I thought I'd document the learning process while I build.
Here goes nothing.
Creating My Token
First of all, I think it might be easier to clarify that there are several kinds of tokens, each corresponding with different token standards, and inheriting the properties of said token standards.
There are two things you need to understand: EIPs and ERCs. I plan to do a series explaining what ERCs and EIPs are in the future, but I'll briefly explain what they are here.
EIP is an acronym for "Ethereum Improvement Proposal". Suppose I have an idea for a new kind of crypto token, and I believe in its potential. All I'd have to do is put it in writing (source contract and all) and submit it to the Ethereum community. Once it gets reviewed and approved, it becomes an ERC (or Ethereum Request for Comment).
Therefore, ERC20 defines the token standard for regular cryptocurrency tokens. Interestingly enough, Non-Fungible Tokens (NFTs) have their own token standards (ERC721) as well. So do Semi-Fungible Tokens (ERC1155) and Stablecoins.
Ingredients
Basically, you need a few basic components to make your own crypto. some of them include
- Your token's name (I called mine "Gelatoken")
- Your token's symbol (two or three characters to identify your token by... I called mine GET)
- The token's number of decimal places
Ether, for example, has 18 of these decimal places. This means that one ether can be split into 10^-18 tiny bits, and one of these bits is called a Wei.
I could simply write out all the code contained in the ERC20 token standard from scratch and tweak it to correctly define my token. However, libraries for that already exist, and you can simply use one of these to create your own token. You can do this by using a special property of the solidity programming language called INHERITANCE.
Inheritance
Inheritance is a wonderful little bit of many programming languages, that allows you to simply "inherit" the properties of any existing piece of code, for use in another.
Lucky for you, a library called OpenZepellin exists. OpenZepellin is a compiled library of open-source solidity smart contracts. Basically, the library contains pre-written smart contracts for tokens, DAOs, and basically everything else you need smart contracts written for.
Install the OpenZepellin library by navigating to the root of your token project and running this command in your terminal:
npm install OpenZepellin
Oh, yeah, make sure you have node, hardhat/truffle and all the other necessary dependencies installed. a full breakdown of the installation process can be found here.
install and set up a basic truffle project here, and install/set up a basic hardhat project here.
Create a MyToken.Sol file in your "contracts" folder, specify the SPDX License Identifier and the solidity version in it and import the ERC20 specification from the OpenZepellin Library at the top.
//SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 < 0.9.0;
import "@openzepellin/contracts/token/ERC20/ERC20.sol"
To inherit the properties of the ERC20 token standard contained in the OpenZepellin library you just imported, use the "is" keyword.
contract MyToken is ERC20{
//insert code
}
Viola! You have successfully inherited all of the properties and functions contained in the standard ERC20 implementation. Your code should look like this:
//SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 < 0.9.0;
import "@openzepellin/contracts/token/ERC20/ERC20.sol"
contract MyToken is ERC20{
//insert code
}
Believe it or not, we're almost done here.
Constructors
How do I explain what constructors are?
Constructors are basically functions... they look like this
constructor(){
//insert code
}
The only difference between regular functions and constructors is that constructors are run the very first time a constructor is deployed, cementing whatever you specify in them as the contract's details forever.
The standard ERC20 contract implementation contains a constructor that takes in two arguments.
- Your token's name
- Your token's symbol
See what the original ERC20 implementation looks like on OpenZepellin's GitHub here. You can inherit the constructor of the standard ERC20 implementation in your own project like so:
constructor() ERC20("MyToken", "MYT"){
//constructor details here
}
Here, I specified "MyToken" as my new token's name, and "MYT" as its symbol (much like BTC is bitcoin's, and ETH is ether's).
Your whole code should look like this:
//SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 < 0.9.0;
import "@openzepellin/contracts/token/ERC20/ERC20.sol"
contract MyToken is ERC20{
constructor() ERC20("MyToken", "MYT"){
//constructor details here
}
}
Specifying Your Token's Supply
Next up is your token's total supply. Every kind of money has to have a supply amount, right?
Take bitcoin, for example, which has 21,000,000 bitcoins as its supply (cap). This means that only 21 million of these coins will ever exist.
You set the total supply of your token by writing code in your constructor function as follows:
_mint(msg.sender, 1000000)
The mint function is a standard function in the ERC20 standard implementation and is used to mint (create) new tokens. It takes in two parameters
- the owner of the tokens
- the number of tokens.
In my code, I specified the owner as msg.sender
. in essence, the "sender" or the deployer of the smart contract. At the end of the day, your code should look like this:
//SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 < 0.9.0;
import "@openzepellin/contracts/token/ERC20/ERC20.sol"
contract MyToken is ERC20{
constructor() ERC20("MyToken", "MYT"){
_mint(msg.sender, 1000000)
}
}
And... there you have it! The code for your very own cryptocurrency, ready to be deployed to a testnet for testing, and then to the Ethereum mainnet if you so choose.
One day, maybe, I'll write a post about how easy it is to deploy one of these tokens to a testnet and then to the mainnet using frameworks like HardHat or Truffle.
I bet you already know what the title of my article will be. But until then, I hope I have been able to prove that any moron can make (and possibly deploy) crypto.