新来的?首次访问区块链节点即可享受 30% 折扣!

banner image

How To Create an ERC-20 Token on Ethereum (ETH) 

Vance Wood

Vance Wood

September 14, 2022

19 分鐘閱讀

article cover

In this short manual, the team of GetBlock, a top-tier blockchain nodes provider, describes the shortest way to create ERC20 token. As this standard is the most popular token design on Ethereum (ETH) and all blockchains compatible with Ethereum Virtual Machine (EVM), creating your own ERC20 token might be the first step to Web3.

What is Ethereum (ETH)?

(if you’re more or less familiar with blockchain, crypto, tokens and Ethereum (ETH), please, proceed to the Guide below)

Launched on July 30, 2015, Ethereum (ETH) network is a first-ever smart contracts platform or ‘decentralized computer’. Ethereum (ETH) was founded by Vitalik Buterin, Joseph Lubin, and Gavin Wood. Like Bitcoin (BTC), modern Ethereum (ETH) works on Proof-of-Work consensus, but in September, 2022 it will migrate to Proof-of-Stake consensus.
Ethereum (ETH) pioneered the concept of smart contracts hosting platform. Its distributed computational power supercharges thousands of decentralized applications (dApps) including DeFis, DEXes, on-chain games, NFTs marketplaces, governance systems, and so on.

Despite savage rivalry in its segment - Tron (TRX), Solana (SOL), Cardano (ADA), Avalanche (AVAX) also support smart contracts - Ethereum (ETH) remains largest smart contracts platform.

What is the ERC20 token?

Cryptocurrency tokens (digital currencies, blockchain currencies, cryptos) are all classes of blockchain-based ‘value items’, i.e. analogies of ‘coins’ in classic economy. At the same time, every cryptocurrency token is a smart contract.

ERC-20 token (Ethereum Requests for Comments) is the most popular standard (subclass) of Ethereum-based tokens.

What is the ERC-20?

ERC20 token standard is an attempt to set the pattern for tokens needed for specific use-cases. Before ERC-20 tokens were invented, every Ethereum (ETH) developer had to ‘reinvent the wheel’: introduction of this token standard streamlined the development of Ethereum-based protocols.

ERC-20 tokens can represent various objects in Ethereum’s world: starting from reputation points to digital equivalents to fiat USD, from lottery tickets to in-game points, and so on.

What is the ERC20 Network?

When people refer to ERC-20, they are typically talking about a set of rules and functions for creating tokens within the Ethereum network. This token standard ensures compatibility and interoperability among different tokens on the blockchain.

Variety of cryptocurrency tokens

Ideologically, tokens are designed to transfer value between the participants of the same blockchain ecosystem (account-to-account, account-to-dApp, and so on). As this concept is flexible, there are a plethora of use-cases for cryptocurrency tokens.

Creating a token: Utility tokens

Utility tokens allow the users of crypto protocols to enjoy special benefits or exclusive limited instruments. They work not unlike tokenized membership cards for premium-level users. For instance, holders of Binance Coins (BNB) can trade on Binance, a largest centralized crypto exchange (CEX) with reduced fees.

Axie Infinity Coin (AXS) is a utility token of mainstream on-chain gaming platform Axie Infinity. Some protocols also invite their users to stake utility tokens to get periodical rewards. Chainlink (LINK) protocol requires its users to hold LINK tokens to work with its instruments.

Creating a token: Governance tokens

Governance tokens work like voting instruments in decentralized autonomous organizations (DAOs), a blockchain-based ‘group wisdom’ protocol. Holders of governance tokens can vote in crucial referendums regarding network upgrades, fees policy, marketing activities, compensations for the team and so on.

Governance tokens include Yearn Finance’s YFI, Aave Finance’s AAVE, Decentraland’s MANA: their holders use the tokens to decide on network referendums. MKR in MakerDAO and COMP in Compound are the earliest examples of governance tokens in the Ethereum (ETH) ecosystem.

Creating a token: Liquidity providers tokens or LP tokens

Liquidity provider tokens or LP tokens are used by decentralized cryptocurrency exchanges to reward those crypto holders who support them with liquidity. For instance, Uniswap (UNI), SushiSwap (SUSHI), and PancakeSwap (CAKE) distribute LP tokens between their liquidity providers.

1Inch DEX aggregator supports LPs with its LP tokens 1INCH, as GetBlock covered in 2021.

How to create ERC20 token: Detailed guide

That being said, ERC-20 tokens are flexible general-purpose instruments for various digital economy operations. As such, the right moment has come to learn how to create a token on Ethereum (ETH).

  1. Start with Remix

First of all, we need to open an integrated development environment (IDE). In this tutorial, we are going to use Remix, a most popular web interface for writing and deploying Ethereum (ETH) smart contracts.

In Remix, we choose the ‘Start coding option and create GetBlock_Token workspace (see it in the upper left corner).

GetBlocks_workspace_in_Remix
Context Banner
  1. Sign up on GetBlock and connect to Sepolia

In order to make our code ‘work’, we need to connect our codebase to a blockchain itself. Technically, we need to establish and activate the bridge between our application and blockchain nodes. As we’re creating ERC20 tokens on Ethereum (ETH), we should therefore interact with Ethereum (ETH) nodes.

To make our experiment more cost-effective, we will work with a testing network of Ethereum (ETH) - a sandbox environment that emulates technical specifications of Ethereum (ETH) mainnet. Ethereum (ETH) has different testnets including Holesky and Sepolia.

We will work with Sepolia, a testnet launched by the Ethereum (ETH) team in 2021 GetBlock offers secure and reliable connection to all mainstream Ethereum (ETH) testnets including Sepolia.

To use GetBlock, first, you need to register an account and sign it. Then, in the ‘Shared Nodes’ menu, we need to choose ‘Ethereum’ and switch the network to ‘Sepolia’.

GetBlocks_shared_nodes_menu

In the ‘API’ list, we need to choose JSON-RPC;. Click ‘Get’ and here’s our endpoint to Ethereum’s testnet.

  1. Connect Metamask to Sepolia Testnet

Then, we should install and customize wallets for Ethereum (ETH) tokens. Metamask is the most popular one: it can be installed into Chrome browser as a plug-in. Once the wallet is installed, we need to add Sepolia to your Metamask.

Adding_Sepolia_to_MetaMask

In the list of networks available, we need to choose ‘Add Network’ and set the parameters :

Network Name: Sepolia Test Network

New RPC URL: https://go.getblock.io/

ChainID: 11155111

Currency: SepoliaETH

Block Explorer URL: https://sepolia.etherscan.io

That’s it, now the wallet supports Sepolia as one of its chains.

Then, you need to get some testnet money from a faucet. You can use https://bwarelabs.com/faucets/ethereum-sepolia

  1. Import the code from OpenZepellin

In order to streamline the process of development, we can take almost ready-made code standards for ERC-20 tokens from OpenZepellin. OpenZepellin Contracts is a library for smart contracts building: its collection of code templates features a plethora of patterns for various use-cases.

Here’s how the standard for ERC-20 token looks like (‘GLDToken’, ‘GLD’, and ‘Gold’ are the names for the token we’re experiment with):

// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract GLDToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("GETBLOCK_TEST", "GBT") {
        _mint(msg.sender, initialSupply);
    }
}

As such, we can take it and run it in Remix:

Running_Code_For_GetBlockToken

Then we need to compile the code via ‘Solidity compiler’, a special program that translates a programming language's source code into machine code or bytecode. Compiler can be found in the left bottom of the screen (the button with the Solidity programming language logo).

Compiling_Code_For_GetBlockToke

Once compiled, our code is ready for deployment to testnet. Let’s enter the Deployment menu (next to the compiler’s one). In the ‘Environment’ field, let’s set ‘Injected Provider’ as we’re working with testnet and the address of our account in Sepolia.

CompilingCode_For_GetBlockToken

As the last step, we need to confirm the deployment via a MetaMask wallet by approving a transaction and paying a small gas fee – the cost to create our ERC20 token.

That’s it: now we can track our token in any Ethereum (ETH) explorer, i.e. Etherscan:

GetBlockToken_In_Etherscan

Closing thoughts

Now we know how to deploy Ethereum’s tokens of ERC20 standard. It unlocks enormous opportunities: we can create digital economical systems from scratch using the disruptive power of the largest smart contracts platform.

Vance Wood

Vance Wood

September 14, 2022

19 分鐘閱讀

twittertwittertelegramtelegramLinkedinLinkedin