Introducing the Tokens Plugin

indreams.eth
0xC09D
February 8th, 2022

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:

ERC20-Factory

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:

  • Deploy a new token: using the factory, call the create function. Most parameters are self-explanatory. A few parameters to watch out for:
    • The 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.
    • For the decimals parameter, we suggest using 18 decimals, as most ERC20 tokens use that.
    • For the 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.
  • See your token’s address: After you deploy a new token, there are two ways of seeing your token’s address:
    • First, on the deployment transaction, you will see a “Tokens Transferred” section; This token transfer represents minting the initial supply to the owner’s wallet. If you click on your token’s name, that will take you to the token’s page on Etherscan.
    • Second, on the deployment transaction logs, you can see multiple events; The last ERC20Deployed event gives you information about your token deployment. The clone parameter is your token’s address.

ERC20 Logic

Ownership

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:

  • Transfer ownership: The ERC20 uses the two-step “ownable” pattern to ensure that the new owner has the ability to submit transactions and ownership is not lost accidentally. First, the current owner needs to call transferOwnership(address nextOwner_) specifying the new owner. After that, the new owner needs to call acceptOwnership.
  • Renounce ownership: to renounce ownership, the owner can call renounceOwnership.

Minting and Burning

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 new tokens: the token owner can all mint(address to, uint256 value).
  • Determine the burn setting: the token owner can call setBurnable(bool canBurn).
  • Burn tokens: if the token is burnable, any user can call 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.

Gasless Approvals

The Mirror ERC20 token supports EIP-2612, which allows users to grant token approvals with signatures that don’t incur gas fees.

Clones

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.


Give it a go

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!

Arweave TX
hrgRwtb4ycKUrgaTdj1r8HFvokA6tcFVfuyPVV6jbvI
Ethereum Address
0xC09D3402515676B81a2F768C365146ea3faa5605
Content Digest
qjCohgfeA-WR-ouz349aa3WdqgB-ek6ZgiuNmLUN4AQ