Deploying your own ERC20 Token
Fungible Token Standard
At this point of this chapter, you have become familiar with the design and implementation of the ERC-20 token standard. Still, you might have the following question: how does one actually go about deploying ERC-20 tokens? In this section, we will cover the following deployment methods:
- Custom Deployment
- OpenZeppelin Wizard Contract Deployer
Custom Deployment
By custom deployment, we mean writing your own ERC-20 contract by hand. Right off the bat, this option offers the most customization as you are fully in control over the implementation details of your ERC-20 token. As long as you adhere to the ERC-20 token interface, your token is able to be used by any ERC-20 compatible protocol. However, consider the following downsides of writing your own ERC-20 token by-hand:
- Security: by writing your own custom code, you are putting your ERC-20 token at risk of being hacked by malicious actors. Even the best of programmers can fall victim to security vulnerabilities related to ERC-20 contracts!
- Gas Inefficiencies: it could be that while your contract is "correct," it may be expensive for users to interact with your ERC-20 contract.
The two reasons above, in additions to other small nuances, make it evident that writing your own ERC-20 token from scratch is not the best idea. This leads us to the other option:
OpenZeppelin Wizard
OpenZeppelin's Wizard Contract Creator is a useful tool which allows for developers to deploy contracts on the fly. By this, we mean that by just filling a couple of fields and selecting a few options, we can autogenerate the code necessary to deploy a ERC-20 token to our liking! To get started, head over to wizard.openzeppelin.com/#erc20 where you will see the following:
Front and center, you will see some Solidity code. At first, it seem as if this ERC20 contract OpenZeppelin has generated for us contains basically nothing. However, if you look closely, you will see that the MyToken contract that OpenZeppelin has generated for us inherits the ERC20, ERC20Permit contracts, which are defined and contain all the logic for our ERC-20 contract. This is the great part about the OpenZeppelin Wizard Contract Creator - we can easily modify our ERC-20 contract by inheriting the contracts whose functionalities we want. Therefore, as an example, let's create the following contract:
In the above, we've created a new ERC-20 contract named BigRedCoin. Furthermore, this ERC-20 token allocates to the deployer 20000 tokens on initialization and gives the owner full rights over the behavior of the token. Now that we have our ERC-20 token contract customized, how do we actually deploy it?
If you look at the righthand side of the Wizard page, you will see the button Copy to Clipboard. As the name might suggest, this allows us to copy our contract and paste it to a file in our Avalanche Starter Kit, which we can then compile and deploy onto the blockchain!