Deploy ERC20 Token

In this post we‘ll go over an erc20 token factory contract that deploys a token with a single click. The dapp is built with React, Truffle, Drizzle, Metamask, and Zeppelin-Solidity. Repo available here.

Rinkeby Factory Instance

A factory instance deployed to Rinkeby test net is available here — you need to have Metamask installed and need to be connected to Rinkeby network.

The UI is very simple:

Token Deployer UI.

For the dapp to work properly you need to:
- Make sure you have Metamask installed
- Select Rinkeby Test Network
- Make sure you have some test ETH in your account

Metamask injects Web3 and the account you are using is displayed. The form accepts two parameters: your Token Name and your Token Symbol. For simplicity the total supply is hard-coded to be:

uint8 public constant decimals = 18;
INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals));

After typing your token name and symbol hit the button and Metamask will ask for confirmation:

Metamask waiting for confirmation.

After you confirm your transaction it will be submitted, mined, and then the UI will update:

Token successfully deployed.

The dapp shows a message indicating the transaction was successfully submitted and it updates the footer with your token contract address and the transaction hash, you can verify this using Etherscan:

Transaction success in Etherscan.

Now simply use your token contract address to add your token to your Metamask:

Add your new token to Metamask.

That’s it! You can now send your new token to anyone!

Token Factory

The token contract is a simple modification of Zeppelin-Solidity’s erc20 standard token:

For simplicity purposes the INITIAL_SUPPLY is set to be a fixed value but you could simply pass it as an extra constructor parameter if you like. The constructor takes the _name and _symbol variables and allocates them, finally the total supply is sent to the _owner.

The token factory contract is given by:

The constructor creates a new MyToken instance and sets the appropriate parameters. MyTokenFactory inherits methods from Factory.sol like register.

That’s it! If you would like to work on this dapp or make suggestions here is the repo and the Heroku dapp.

Thank you very much for reading this post! If you found this post useful please clap on this article and make sure to follow me for more regular content, also check out my Github as I regularly post sample code and projects. If you have any questions feel free to reply below this post or shoot me an email.

Happy coding!