📝 在 Twitter 上分享您的反饋並索取 100 萬個免費 GetBlock 請求

How To Create an ERC-20 Token on Ethereum (ETH): GetBlock’s Step-by-Step Manual

Vance Wood

Vance Wood

September 14, 2022

8 分鐘閱讀

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 ERC20 token might be the first step to Web3.

What are smart contracts?

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

Smart contracts are small software programs that are executed only when specific conditions are met. They are stored in blockchains, and, therefore, are signed by two or more blockchain (cryptocurrency) addresses.

Smart contracts are agreements: each of them implements this or that business logic. For instance, the simplest smart contract might look like ‘If Alice’s balance reaches 100 coins, she should transfer 5 coins to Bob’ whereas ‘coins’ are cryptocurrencies (blockchain-based items) while ‘Alice’ and ‘Bob’ are blockchain addresses.

Smart contracts are essential elements of decentralized applications including decentralized finances protocols or DeFis. Every decentralized crypto exchange, stablecoin module, and liquidity pool has the architecture of smart contracts under its hood.

Smart contracts can work on the top of programmatic blockchains i.e. the blockchains that can’t be programmed for operations more sophisticated than sending crypto from one account to another. First-gen blockchains like Bitcoin (BTC), Litecoin (LTC), Dogecoin (DOGE) don’t support smart contracts unlike Ethereum (ETH), BNB Chain (ex. Binance Smart Chain or BSC), Solana (SOL) and Cardano (ADA).

What are cryptocurrency tokens?

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. Thus, technically, crypto tokens are a subclass of smart contracts.

It means that every token is an agreement between at least two accounts of the blockchain. 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.

What is Ethereum (ETH)?

As we mentioned above, smart contracts and tokens are run by blockchains or decentralized computational systems. 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 thanks to its

What is the ERC20 token?

ERC-20 token (Ethereum Requests for Comments) is the most popular standard (subclass) of Ethereum-based tokens. 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.

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 online’ option and create GetBlock_Token workspace (see it in the upper left corner).

ERC20_1

2. Sign up on GetBlock and connect to Goerli

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 Kovan, Ropsten, Rinkeby, Sepolia, and so on.

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

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 button to ‘Testnet’; ‘Goerli’ should be chosen as the name of the test network.

GetBlocks_shared_nodes_menu

In the ‘Endpoint’ list, we need to choose https-endpoint; here’s our endpoint to Ethereum’s testnet Goerli.

3. Connect Metamask to Goerli 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 Goerli to your Metamask.

Adding_Goerli_to_MetaMask

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

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

Then, you need to get some testnet money (GoerliETH) from a faucet. You can use https://faucet.paradigm.xyz/ (active Twitter account required).

4. 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_GetBlockToken

Once compiled, our code is ready for deployment to Goerli 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 Goerli.

CompilingCode_For_GetBlockToken

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

GetBlockToken_In_Etherscan

Now we can track our token (contract) 0x4E8fBD0d754a9D06D7B202DA18458FDE1Ba9487f in Goerli testnet.

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

8 分鐘閱讀

twittertwittertelegramtelegramLinkedinLinkedin