Build and Deploy Your Own Cryptocurrency on the Ethereum Network

Build and Deploy your own Cryptocurrency on the Ethereum Network

Hi there! it’s been a while now since I wanted to create some projects around blockchain, and I have lately been playing around with Ethereum and how to develop smart contracts using the Solidity programming language. Today I want to share with you what was my first project, the creation, and deployment of an ERC20 token.

In this article, we will provide the code for a simple cryptocurrency as well as all the steps that are necessary to get your token up and running on the Ethereum network.

For those interested in a more visual experience, I recorded a full session explaining all the contents of this article and doing the programming and deployment live. You can watch the view here:

Let’s get started!


Requirements

There are a few things that we need to prepare in advance before creating our token, and those are described below.

Select your Ethereum network

You probably know Ethereum and its network, however, did you know that there are multiple instances of Ethereum running? Most people are familiar with the main Ethereum network, where all the transactions are running, and where all exchanges operate (or at least should). But there’s more to it, there are alternative networks running the same code as the main instance for example for testing purposes. An example of this is the “Ropsten Test Network” which we will be using today to deploy our code.

One of the benefits of using a test network is that, not only we can submit any code we want and test it out, but also we can do it free of charge. Every time a new token is created, it is necessary to register a transaction on the Ethereum network it is running. And this transaction will come with a GAS fee which we will need to pay with Ethereum from the network.

If we are on the main network of Ethereum, we would have to use actual money, like EUR or USD, to buy Ethereum first, and then create our token. Not very convenient to just try it out. However, the beauty of the test network is that we can get free Ethereum using applications called faucets. Now, this is just fake ETH, so we can’t sell them to anyone or anything, but it’s good enough to deploy our test tokens.

Wallet & Account

Now that we know which network we want to use to build and deploy our token, we need to create a wallet and an account into that network. I strongly recommend that you use MetaMask for this task.

MetaMask is an extension that runs as an extension on your browser and allows you to create accounts in multiple networks and it has integrations with the deployment interfaces we are going to be using today, making the job much easier than with any other method.

So download MetaMask and set it up on your browser creating an account on the Ropsten Test Network. This process is super easy and guided, so I won’t get into many details.

Next, you will need some fake ETH in your account. For that, you need to run an application called “faucet”. You can use a Faucet from MetaMask itself at https://faucet.metamask.io/ , it’s super easy and it will connect your account automatically and will send you 1 ETH.

Alternatively, you can simply google “Ethereum Faucet” and select one of the hundreds out there. Normally they will ask you for your account number (public) and with only that information they will transfer you X amount of ETH, normally 1, which is more than enough for our purposes.

Token Information

Next, we need to think about the cryptocurrency we want to create and what properties are those going to be. You will need the following information before we actually get started:

  • Token Symbol: This is an identifier for the token, for example, the token for Bitcoin is BTC. You can use from 3 to 5 alphanumeric characters for the selection.
  • Token Name: e.g. Bitcoin or LCS Token
  • Total Supply: How many tokens do we want to be created in total
  • Decimals: How many decimals you can use to break a token, e.g. “0” decimals makes the token binary, either you have a token or you don’t. “2” decimals allows you to fraction a token, being the smaller size 0.01; and you can add up to “18” decimals.
  • Owner Account: Account in the same network as the token which will receive the tokens upon creation. It can be the same account as the account used to pay for the GAS fee, as we will do in our example below.

Code

Last but not least, you will need to code which will run our own cryptocurrency. I’ve already prepared for you a sample code that will implement the ERC20 specification and will give you basic cryptocurrency functionality.

You can download the code here:

https://gist.github.com/bajcmartinez/c1cefbb3b1375d037f07b7b779568e42/


Updating the Code

The first thing you need to do is to update the code, you can either download the file I provided or copy and paste the contents in your favorite text/code editor. Once there you will notice at the beginning of the file something like:

pragma solidity ^0.4.24;

// ----------------------------------------------------------------------------
// Sample token contract
//
// Symbol        : {{Token Symbol}}
// Name          : {{Token Name}}
// Total supply  : {{Total Supply}}
// Decimals      : {{Decimals}}
// Owner Account : {{Owner Account}}
//
// Enjoy.
//
// (c) by Juan Cruz Martinez 2020. MIT Licence.
// ----------------------------------------------------------------------------

The first line of code is simply required to run any solidity program, but the rest is where it gets interesting. Though it’s actually all commented code, meaning that it has no relevance during execution or compilation, it does contain the variables we discussed we needed before we can actually deploy to the network.

What I did to facilitate how to work with the code, is that each of these variables needs to be assigned a value, and once they are all completed, you will have the code ready and this comment section will be a nice description of our token.

So, how we go about updating it? For each variable, I assigned a code wrapped in {{ }}. You need to find and replace all occurrences with each one of them. This is very easy to do in any code editor.

Let’s start with an example, find and replace all occurrences of {{Token Symbol}} for your token symbol, in my case: LCSTK, no ned of quotes here.

After replacing it should now look like this:

pragma solidity ^0.4.24;

// ----------------------------------------------------------------------------
// Sample token contract
//
// Symbol        : LCSTK
// Name          : {{Token Name}}
// Total supply  : {{Total Supply}}
// Decimals      : {{Decimals}}
// Owner Account : {{Owner Account}}
//
// Enjoy.
//
// (c) by Juan Cruz Martinez 2020. MIT Licence.
// ----------------------------------------------------------------------------

And please do the same for the token name.

Next, we need to specify the total supply and the decimals, which go hand by hand. You may be wondering why. Let’s assume an example to explain. Let’s say we want to create a binary token, either I have a token or I don’t, but I can’t have 0.5 of a token, and we also want a total of 1000 tokens to be created. Then our variables would be replaced as follows:

Total Supply: 1000
Decimals: 0

However if we want to have some decimals, say, 2 decimals, then we would need to modify the total supply, by adding a zero for each decimal at the end of the desired number. Meaning that if we wanted 1000 to be the total supply, we need to update our code to be 100000 (1000 + 00), let’s see how it looks like now:

// ----------------------------------------------------------------------------
// Sample token contract
//
// Symbol        : LCSTK
// Name          : Live Code Stream Token
// Total supply  : 100000
// Decimals      : 2
// Owner Account : {{Owner Account}}
//
// Enjoy.
//
// (c) by Juan Cruz Martinez 2020. MIT Licence.
// ----------------------------------------------------------------------------

Awesome, we are almost there. We now only need to specify the account which will receive all the tokens that get created. Head to MetaMask and copy your account number, and once more, find and replace the variable in all occurrences. At the end your code should look like this:

// ----------------------------------------------------------------------------
// Sample token contract
//
// Symbol        : LCSTK
// Name          : Live Code Stream Token
// Total supply  : 100000
// Decimals      : 2
// Owner Account : 0x6009f738dcF7194EfddDfc3B13Ce325e21A05175
//
// Enjoy.
//
// (c) by Juan Cruz Martinez 2020. MIT Licence.
// ----------------------------------------------------------------------------

NOTE: it is very important that you use “find and replace all occurrences” or you will have compile errors later in the process. Our file is now ready for deployment, that easy!


Deployment

The good people from Ethereum provide us with an IDE (integrated development environment) that is fully capable of handling the full process, from editing the files, building, and deploying, among many other things.

This IDE named “Remix” can be accessed easily through the browser by visiting:

https://remix.ethereum.org/

Once there you will see a screen like the following:

Remix Homepage

Remix Homepage

The first section we see on the left is our contextual menu, and in the right section we see the welcome screen. As we are by default on the file explorer the contextual menu shows all the files and folders that are available.

You will need to create a new file here by clicking on the “+” button near the “browser” folder on the left panel. There are already a few files in there now, but you can ignore them. You can name the file to your likes, it’s not relevant for the process.

Once the file is created simply past the code that we worked on your text editor. It should more or less look like this:

Remix File Explorer

Remix File Explorer

Our code is now ready to be compiled. For that, look at the icon bar on the left of the corner. Right now we are on the first icon “File Explorer” but we need to open the second tab “Solidity Compiler”

Remix Solidity Compiler

Remix Solidity Compiler

Once there hit “Compile” and if all is good, you should see some options appearing in the contract drop downfield, one of them being your token contract. (Token Symbol + “Token”)

With everything looking good we just need to deploy the code, head now to the 4th tab on the menu “Deploy & Run Transactions”.

Remix Deploy & Run Transactions

Remix Deploy & Run Transactions

There are here a few things we need to change before we actually hit “Deploy”. The first is, as we are using MetaMask, we need to change the “Environment” from “JavaScript VM” to “Injected Weg3”.

The moment you do that, MetaMask will prompt you to confirm that you want to connect your MetaMask wallet to Remix, hit confirm.

After you do that, your account will automatically populate the “Account” filed below with the account number and your current balance in ether.

Lastly, we need to specify we want to deploy, make sure you select your contract from the “Contract” dropdown field. Your token contract is your token symbol + “Token”.

Last, hit “Deploy”.

The deployment process may take anywhere from a few minutes to up to who knows how many minutes depending on the status of the network at that time. Usually, I found that Ropsten will take 2 to 3 minutes, and the maximum wait time I had was 10 minutes.

After the process is complete you will receive a confirmation on the screen with the information of your deployed contract, including the address where the code got saved.

That’s it! Your token is now live. But how do you see it?

Configuring MetaMask to Retrieve My Token

Up to this point, our token already exists in the Ethereum network and can be used to transact, however, how do you access your tokens? Turns out that MetaMask as well as other walltes can already operate with your token as it follows a specification called ERC20.

However wallets are not yet aware of the existence of your token, so you will have to manually add them. Let’s see how that works on MetaMask, but before we leave Remix, there’s one last thing we need to do.

When the deployment process completed we ended up with a screen like this:

Remix Deployed Contract

Remix Deployed Contract

With a section called “Deployed Contracts” and right bellow our Token contract information. One important data on that screen is the address where the code got deploy, please copy that using the copy icon on the right, highlighted in the picture above.

And with that code open MetaMask, and click on “Add Token”. This will pop up a screen with 2 tabs, switch to the second tab called “Custom Token” and paste the address you copied in the contract address field. This will automatically populate the token symbol and decimals fields.

After that click “Next” then “Add’ and you are done! You can now see your tokens on your MetaMask wallet.


Conclusions

Today we learned how to build and deploy your own cryptocurrency by following the ERC20 interface and utilizing Remix and MetaMask. The process is super easy, and the code we provided though working is just a minimal example. You can build many great things on top of what we did today, and I hope I can hear from you all the great projects that you build using the power of blockchain.

I really hope that you enjoyed this tutorial. It’s the first time as well that I record myself and publish content like this on youtube. I’d appreciate any feedback, I know I still have much to learn, but I’ll get there, I promise.

Thanks for reading!

If you liked what you saw, please support my work!

Juan Cruz Martinez - Author @ Live Code Stream

Juan Cruz Martinez

Juan has made it his mission to help aspiring developers unlock their full potential. With over two decades of hands-on programming experience, he understands the challenges and rewards of learning to code. By providing accessible and engaging educational content, Juan has cultivated a community of learners who share their passion for coding. Leveraging his expertise and empathetic teaching approach, Juan has successfully guided countless students on their journey to becoming skilled developers, transforming lives through the power of technology.