Create an ERC20 using Remix, without writing Solidity

In this tutorial we will use a Preset ERC20 contract in OpenZeppelin Contracts v3.x to create an ERC20 using Remix, without having to write any Solidity code.

Setting up the Environment

Open https://remix.ethereum.org/ in your favorite browser.

If you haven’t used Remix before, you need to setup plugins so that you can use the Solidity Compiler and Deploy and Run Transactions.

Select the Solidity button under the Environments heading and this will add the required plugins.

The plugins are shown on the left hand column.

Importing the contract

We are going to use Preset ERC20PresetMinterPauser which is an ERC20 that is preset so it can be minted, paused and burned.

We need to import ERC20PresetMinterPauser into Remix.

In the File Explorer press the :plus: to Create New File
Call the new file OpenZeppelinPresetContracts.sol

In the new file add the import statement for ERC20PresetMinterPauser below.

We specify a minimum version of the Solidity compiler to use and import ERC20PresetMinterPauser from GitHub.

Note: When importing via GitHub, you should specify the release tag, otherwise you will get the latest code in the master branch. For OpenZeppelin Contracts you should only use code published in an official release. We will import OpenZeppelin Contracts v3.0.1. (see Importing from GitHub in the Remix documentation).

pragma solidity ^0.6.2;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.1/contracts/presets/ERC20PresetMinterPauser.sol";

Compile the contract

Select the Solidity Compiler plugin.
Press the Compile button to compile the contract.
The contract and the contracts it inherits from will be loaded into Remix.
The contract will then be compiled.

Deploy the contract

We can deploy our new token to a development blockchain. Providing a name and a symbol as parameters to the constructor to create a new ERC20PresetMinterPauser.

Select the Deploy & Run Transactions plugin.
Environment should default to JavaScript VM, our development blockchain.
Change the gas limit to 4000000
Change the Contract to ERC20PresetMinterPauser
Specify the name and symbol to use for our new token. I am using “My Token” and “MYT”
Press Deploy.

Remix will deploy our token.

Interact with our Token

We can interact with our deployed token using Remix.
In the Deploy & Run Transactions plugin, under Deployed Contracts expand our deployed token (ERC20PRESETMINTERPAUSER) to show the functions we can interact with. (for help see Deployed Contracts Remix documentation)

Token metadata

We can call the contract functions to read token metadata such as name, symbol and decimals
Press the name, symbol and decimals function buttons and this will call the functions in our deployed token.
Showing values:

  • decimals: 0: uint8: 18
  • name: 0: string: My Token
  • symbol: 0: string: MYT

Mint

We can send a transaction to mint tokens to a given account, from an account with the minter role.
In our case we are minting from the account which deployed the token, which is given the minter role.

We will mint 1000 tokens (the token has 18 decimals) to our account: 0x172DA24DecdA4836582e48f4ac626242a35e797E

We can set the parameters as follows
"0x172DA24DecdA4836582e48f4ac626242a35e797E","1000000000000000000000"
Press mint
The transaction will be shown in the console

We can check the balance once the transaction has completed by calling balanceOf and specifying the address "0x172DA24DecdA4836582e48f4ac626242a35e797E"
0: uint256: 1000000000000000000000

Burn

We can send a transaction to burn tokens (from the account holder) of 100 tokens (18 decimals)
"100000000000000000000"

We can check the balance after burning once the transaction has completed by calling balanceOf and specifying the address "0x172DA24DecdA4836582e48f4ac626242a35e797E"
balanceOf: 0: uint256: 900000000000000000000

Pause

We can pause our Token by sending a transaction calling the pause function, from an account with the pauser role.
In our case we are pausing from the account which deployed the token, which is given the pauser role.

Press pause

Transactions which attempt to transfer (such as mint) will revert whilst paused.

We will mint 1000 tokens (the token has 18 decimals) to our account: 0x172DA24DecdA4836582e48f4ac626242a35e797E

We can set the parameters as follows
"0x172DA24DecdA4836582e48f4ac626242a35e797E","1000000000000000000000"
Press mint
The transaction will revert in the console with reason "ERC20Pausable: token transfer while paused"

Next steps