With our recent release of Plugins, we also debuted the ability for creators to deploy their own ERC20 tokens in seconds on Mirror. And with not just any contract—this is the most finely tuned and efficient way to mint an ERC20 token around. To get started simply connect your wallet and enable the Tokens plugin.
To celebrate, we’re going to do a deep dive on the ins and outs of ERC20 Token minting on Mirror. In this post, we’ll look at how the ERC20 factory contract works on-chain in order to explain some of the advanced functionality available to power users. Additionally, we invite the broader web3 ecosystem to integrate our ERC20 token factory into their products, as we believe we’ve struck the right balance between token flexibility and low gas deployments necessary for a neutral and efficient public good primitive.
You can find the deployed contracts at:
The ERC20Factory
is a contract that facilitates the deployments of new ERC20 tokens for creators. The factory uses the EIP-1167 standard for simply and cheaply cloning contract functionality. Another benefit of using clones is that we can predict the address to which your token will deploy before submitting the transaction.
When you deploy a token with the ERC20Factory you will have the option to specify an owner and a total supply. The total supply will be minted to the owner’s wallet.
The easiest way to interact with the contract is via the Token plugin in your Mirror dashboard, Advanced readers can interact directly with the factory contract on Etherscan by reading along!
How to:
create
function. Most parameters are self-explanatory. A few parameters to watch out for:
totalSupply_
parameter needs to be specified in Wei; You can use Etherscan’s Unit Converter tool for this; simply type the decimal value you want in the Ether
box and copy/paste the Wei
value into the totalSupply_
parameter.decimals
parameter, we suggest using 18 decimals, as most ERC20 tokens use that.nonce
parameter, you need to pass in an integer; This parameter is used on the cloning functionality. For advanced details, see the Clones section below.ERC20Deployed
event gives you information about your token deployment. The clone
parameter is your token’s address.The Mirror ERC20 implementation allows for creators to set a token owner, which is an Ethereum account/wallet that controls a few settings on the token. Token ownership can be transferred to any other address or renounced altogether, effectively making settings immutable. This means a token’s supply can be made fixed by renouncing ownership.
How to:
transferOwnership(address nextOwner_)
specifying the new owner. After that, the new owner needs to call acceptOwnership
.renounceOwnership
.The contract owner
can mint new tokens to any address and determine a “burn” setting. A burn setting determines whether the tokens can be burned. Burning reduces the circulating supply of a token, which affects its tokenomics. Token creators should have the ability to decide if their tokens can be burned.
How to:
mint(address to, uint256 value)
.setBurnable(bool canBurn)
.burn(uint256 value)
to burn their own tokens.You might be wondering, “Why would you want to burn your tokens?!” The answer to that is that it really depends on how want your token to be used. Burning tokens can facilitate different types of dynamics; For example, Mirror’s own $WRITE token uses the burning functionality to mint a new type of token in exchange -- an ENS domain with a mirror.xyz
extension.
The Mirror ERC20 token supports EIP-2612, which allows users to grant token approvals with signatures that don’t incur gas fees.
The ERC20Factory
uses the EIP-1167 standard for simply and cheaply cloning contract functionality. When you deploy your ERC20 token, what you’re really doing is deploying a very small amount of code that will hold your token’s state (balances, name, symbol, etc.), but will delegate the code logic to a different address.
A benefit of using clones is that we can predict the address to which your token will deploy before submitting a transaction. To deploy a clone to a predictable address, we need to generate a unique salt
parameter. This parameter is generated using your wallet address, your token’s name, symbol, total supply, and the nonce
parameter. The nonce
parameter provides an extra amount of entropy to avoid collisions when generating the salt
parameter. For this reason, you can choose any integer as the value for nonce
as long as you have not previously deployed a token with the exact same parameters.
We’re excited to continue creating powerful and focused plugins like Tokens. To stay in the loop make sure to follow Mirror on Twitter. As always, you can get started anytime by simply connecting your wallet and installing the Token Plugin. Mirror is hiring!