DEV Community

Cover image for Create Your Own Ethereum Token in Minutes
Simon Pfeiffer for Codesphere Inc.

Posted on

Create Your Own Ethereum Token in Minutes

As more and more dollars are poured into blockchain companies, blockchain development has become an increasingly lucrative skill. In this tutorial, we’re going to be using Solidity, an Object-Oriented programming language for building smart contracts.

How Creating a Token Works

We are going to be making what’s known as an ERC-20 token, which is a standardized template for how an Ethereum token works. While our token can function as any other cryptocurrency, it will be run on the Ethereum blockchain, instead of running on its own blockchain.

To define the logic of our ERC-20 token, we will create a smart contract which dictates how the token can be minted, transferred, and burned. As long as your token conforms to the ERC-20 standard, it would be able to be used on most blockchain platforms.

Since we don’t want to deploy this token on the actual Ethereum network(That would cost money), we will be using a test network called Rinkeby. Rinkeby operates exactly like the Ethereum network, except we can give ourselves free ethereum whenever we want. This makes it much easier to test smart contracts and tokens.


Setup

I’ll give the warning now that setting this up is not a quick feat. For all the hype, blockchain technology is still pretty new and most blockchain devtools have pretty bad UX. Nevertheless, let’s march onward!

The first important step is to make sure that you have MetaMask installed on your browser and your wallet setup. MetaMask is a browser extension that allows you to easily access your crypto wallets and interact with blockchain platforms. Once your MetaMask is setup, make sure to navigate to settings and enable show test networks (it will be in the advanced settings tab).

Image description

Now that we can use test networks with our MetaMask, head to the ChainLink Faucet and give yourself 0.1 test Eth on the Rinkeby network. A faucet is a place where you can mint new Eth to your wallet on a test network.

Image description

Finally, we’re going to be using an online Solidity compiler, Remix, to write, compile, and deploy our code on the test network.


Coding our Token

We are going to be making a pretty boilerplate ERC-20 token. To demonstrate how you can add your own logic, I’m going to show how you can set time restrictions on certain actions.

To get started, create a new solidity file (with a .sol extension) in Remix IDE. I’m going to name mine codesphereToken.sol, but you can name it whatever you want.

We’ll then add the following code:

Notice that we are using OpenZeppilin’s ERC20 template as a baseline for our contract. We can then edit the functions as necessary to add our custom logic.

In this example, we made it so new money can’t be minted on fridays.


Deploying and Testing our Token

So how can we compile and test our cryptocurrency? First navigate to the compiler tab and make sure you have the latest commit selected. Keep in mind that the above gist uses Solidity version 0.8.11, you will need to change the pragma line at the beginning if that is no longer the case.

You can then press compile – Remix will notify you of any errors

Image description

Once your code is compiled, head to the deploy tab and select “Injected Web3” for the environment. This should prompt MetaMask to ask you for your sign in.

Make sure that you have the Rinkeby Test Network selected in Meta Mask. You will end up paying with real ETH to deploy your contract if you are on the main Ethereum network.

Image description

Next, select your token under the Contract tab. Before deploying, double check that you are on the Rinkeby test network. If all goes right, MetaMask should ask you to pay a gas fee(With Rinkeby Test Eth) and you should see a successful deployment message after a couple seconds.

Image description

Once the contract has successfully deployed, the following interface will popup:

Image description

This will allow you to test a number of functions such as:

  • Checking the supply, name, or symbol of the token
  • Check the balance of a wallet
  • Mint new tokens to a wallet
  • Transfer tokens between recipients

Where to go from here

Now we of course have only scratched the surface of Ethereum, Solidity, ERC20 tokens, and smart contracts. I hope, however, that this tutorial serves as an effective conduit for you to learn more about these topics.

So what do you want to build with Solidity? Let us know down below!

And as always, happy coding from your good friends at Codesphere, the most intuitive cloud provider ever created.

Top comments (0)