Deploy a Token Contract
Learn how to develop and deploy a token contract on GIWA.
What is ERC20?
ERC20 is the token standard on Ethereum. An ERC20 smart contract manages fungible tokens — meaning every token is identical, with no special privileges or behaviors. In other words, one token owned by someone else has exactly the same value as one token you own. Because of this, ERC20 tokens are commonly used as a medium of exchange, voting, staking, and more.
The ERC20 standard defines 6 required functions and 3 optional functions that a smart contract must implement.
The required functions are as follows:
totalSupply: A method that defines the total supply of the token.balanceOf: A method that returns the number of tokens held by a wallet address.transfer: A method that transfers a specific amount of tokens from the caller to another user.transferFrom: Another type of transfer method used for token transfers between users. Using this method, the sender does not need to call it directly. However, the recipient can only receive tokens within theallowancerange.approve: A method to pre-authorize a certain amount of tokens for a specific user to spend.allowance: A method to check how many tokens one user has authorized another user to transfer.
In addition to the required functions listed above, there are optional functions that improve a token's usability.
name: A method that returns the token's name.symbol: A method that returns the token's symbol.decimals: A method that returns the number of decimal places the token uses. It's used to define the token's smallest unit. For example, if an ERC20 token's decimals value is 6, it means the token can be divided down to six decimal places.
To make a token an ERC20 token, you must implement the ERC20 interface, which requires implementing these six methods.
Developing an ERC20 contract
Across Ethereum and other blockchains, many ERC20-compatible tokens have already been deployed. Some implementations prioritize low gas costs, while others focus on enhanced security.
For robust and secure implementations, many developers rely on libraries like OpenZeppelin or Solady. These libraries provide well-audited, community-verified smart contracts, including ERC20 implementations, making them a trusted choice for token development.
In this example, we’ll use the OpenZeppelin library to build an ERC20 token contract.
Set up the development environment
Install Foundry.
Create a Solidity Project
Install the OpenZepplin library
Write contracts and tests
After writing a contract, you can add test code to verify it behaves as intended.
You can build and test the contract with the following commands.
Deploying the token
You can write a deployment script like the following.
Last updated