How To Make Your Own Cryptocurrency In 10 Lines of Code

Sean
5 min readFeb 9, 2022

About 6 months ago I wrote a blog titled “How to Create Your Own Crypto” which went into detail about things like installing Geth, writing solidity functions, and deploying to the Ethereum blockchain. Since then I’ve found tools like remix.ethereum.org which is an open source web application that allows you to deploy smart contracts to the blockchain.

The beauty of Remix is the way it allows you to import files. The dependencies do not need to be “preloaded” into the File Explorer’s current Workspace before the contract is compiled. So to import a GitHub source file for an ERC20 contract from say OpenZeppelin you could simply type:

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

That might seem like a lot so lets break down what Open Zeppelin is. In short they are an open source platform used for building secure dApps. The framework provides a secure and trusted outline for creating web3 applications. They have frameworks for NFT’s, Cryptocurrencies, etc.

If you would like to check out they’re open projects you can find their GitHub here: https://github.com/OpenZeppelin/openzeppelin-contracts

So now that OpenZeppelin has done the heavy lifting for us let’s look at the actual code that was written in addition to importing their ERC20 framework in order for us to launch our own cryptocurrency.

The top 3 lines of code are just identifying a license, a version of solidity, and importing our ERC-20 standard contract. The real customization begins on line 4 where we get to dictate the name of our contract which I called “CoderCoin” and then linking it to the imported OpenZeppelin contract by adding “is ERC20” pulls in that code.

Essentially, we are extending the ERC20 standard contract we imported from OpenZeppelin. So all the functions and logic that is built into ERC20 is available for us to use, and we can add our own custom logic on top of it.

If you are familiar with Object Oriented Programming principles, you can think of this as a class extending another class.

Next we create a constructor function which runs the first time a smart contract is deployed. For our purposes we need 2 arguments respectively name and symbol. (ie: Name = Ethereum, Symbol = ETH) The string and memory keywords allow memory allocation for the contract information to be stored in.

What happens after is that we call ERC20 which is from the OpenZeppelin contract which has its own constructor which requires us to specify the ‘name’ and ‘symbol’ parameters.

Therefore, we are providing _name and _symbol variables to our contract, which we immediately pass on to the ERC20 constructor, thereby initializing the ERC20 smart contract.

Finally we can call _mint which is an internal function within the ERC-20 standard contract from open zeppelin. This means it can only be called by the contract itself and not from any external users otherwise they’d be able to incrementally mint unlimited coins for themselves.

Since we as the developer want to receive these coins when we create the contract we use ‘msg.sender’ which refers to the person who deploys the smart contract.

The following is the number of tokens you’ll receive based on Ethereum’s unit of prices. 1000 is the token amount you’ll receive and 10 ** 18 is a solidity syntax for 10 to the 18th power. For a further breakdown of Ethereum unit sizes you can check here: https://ethdocs.org/en/latest/ether.html

Compiling and Deploying

You’ve done it! Now all that’s left is to compile and deploy you’re contract. I recommend using a test network first so you don’t waste any precious Ethereum on gas prices.

For Metamask here’s a “faucet” which will provide liquidity to your account and allow you to deploy test contracts. https://faucet.metamask.io/

In Remix IDE on the left hand side you should see a toolbar available that allows you to compile your code.

From there you can go to deploy your contract on the left hand side and remix will ask for your cryptos custom name and symbol as we described in our smart contract.

2 things to keep in mind is to change the environment to Injected Web3 instead of JavaScript VM (London) which is the default on Remix. Also make sure you’re on the Rinkeby or Ropsten test network. From there just pop in your crypto name and symbol and deploy!

If you cant see your tokens right away in your Metamask you might need you to import the tokens.

To do so:

Copy your contract address
Open Metamask and click Import Tokens in the Assets tab

Enter your Token Contract Address from the remix IDE, and it should detect the name and number of decimals automatically!

Click ‘add’ and you will see your balance in Metamask :)

Happy Coding!

--

--