Skip to main content

Deploy Your Own Crypto Token (ERC20)

What is ERC-20 Token?

ERC 20 tokens are issued on the Ethereum network. They have emerged as the technical standard on the Ethereum blockchain for token implementation and provide a list of rules that all Ethereum-based tokens must follow. Side note: Ethereum is a layer 1 blockchain that carries several independent and dependent L1 and L2 blockchains due to its highly automated/virtualized EVM.

‘ERC’ stands for ‘Ethereum Request for Comment.’ ERC-20 specifically has six different coding functions. In terms of implementation of the coding for ERC-20 tokens, the six basic coding functions are as follows:

  1. Total supply
  2. Balance of
  3. Allowance
  4. Transfer
  5. Approve
  6. Transfer from

Create and Deploy your ERC-20 Token using Remix

This step-by-step tutorial will teach you how to create and deploy an ERC-20 token on the Shardeum Sphinx network. We will use Metamask and Remix IDE for this tutorial.

Add Shardeum Network to Metamask/Claim Token

Metamask allows users to store and manage account keys, broadcast transactions, send and receive Ethereum-based cryptocurrencies and tokens, and securely connect to decentralized applications through a compatible web browser or the mobile app’s built-in browser. Click here to install the MetaMask extension on your browser.

Connect to Shardeum with Metamask automatically by following this link and clicking the add network button:

Connect Metamask to Shardeum

Once you are connected to Shardeum in Metamask, claim SHM from a faucet to pay for transaction fees:

Claim SHM from faucets

Writing the Code Using Remix

We are using Remix IDE for writing the smart contract as mentioned above. In Remix, create a new contract file and name it ‘ShardeumERC20Token.sol’ (you can name it anything you want). And, in the contract, write the following code:

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

contract ShardeumERC20Token is ERC20 {

constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol){
_mint(msg.sender, 10000 * 10 ** 18);

}
}

Code explanation in brief for reference:

  1. pragma solidity ^0.8.0 – This line specifies the compiler version of Solidity to be used. ^0.8.0 means any version greater than 0.8.0.
  2. import – This line imports the ERC-20 token standard from OpenZeppelin (OZ).
  3. contract ShardeumERC20Token is ERC20 – This specifies a new contract, named LW3Token, in our Solidity file. Also, it says that this contract is an instance of ERC20.
  4. constructor – Essentially, we created constructor function that is called when the smart contract is first deployed.
  5. _mint – An internal function within the ERC20 standard contract, which means that it can only be called by the contract itself. External users cannot call this function.
  6. 10000 * 10 ** 18 – (which is actually 10 ^ 18) specifies that you want 10000 full tokens to be minted to your address.

Compiling the Smart Contract

Compile the contract by going over to the ‘Compiler’ tab in Remix and selecting ‘ShardeumERC20Token.sol’, and then hit ‘Compile’.

mint_your_own_crypto_1

Deploying the Smart Contract on Shardeum Sphinx

Let’s deploy a fixed supply of 10000 Tokens (You can change it to another supply at the code level).

Go to the ‘Deployer’ tab in Remix.

Select the ‘Injected Web3’ environment (make sure you select Shardeum Sphinx Network), and connect your MetaMask wallet.

Now, select the ‘ShardeumERC20Token.sol’ contract, and enter values for the constructor arguments ‘_Name’ and ‘_Symbol’ as shown in the image below.

mint_your_own_crypto_2

Proceed to click ‘Transact’ and approve the transaction in ‘Metamask’ to deploy your contract!

mint_your_own_crypto_3

You have now successfully deployed ERC-20 Token on Shardeum Sphinx!

After deploying, click the ‘Copy Address’ button to copy the contract address.

mint_your_own_crypto_4

You can now go to Shardeum Explorer and search for contract address and you should be able to see it there!

Video Tutorial