ERC20 Token

Prerequisite:

  • Connect your Web3 wallet to ONUS Chain mainnet or testnet

  • Have some ONUS in your wallet to use as transaction fees

Deploying a new ERC-20 token can be done by using Remix and ERC20 contracts from Open Zeppelin open source.

Step 1. Connect to ONUS chain

Step 2: Code your token in Remix

That’s right, you can code our own ERC-20 token with a few lines of code.

Go to https://remix.ethereum.org/

Remix is a web-based Integrated Development Environment (IDE) for Ethereum smart contract development in Solidity.

Click on the file icon to [Create New File]

Give the new file a name. Like: “mytoken.sol”. Since it is a Solidity file, it should end in .sol.

Now type in the contract code on the right side of the screen.

A few key information in the code:

Contract name: this is the name of your smart contract. This should be the same as the token name. This line defines your token as an ERC20 token.

contract Z1Token is ERC20 {

In the next line we define the name and the symbol (short name) of the token. Here we are creating a token called Z1Token with symbol Z1.

constructor() ERC20("Z1Token", "Z1") {

Next is pre-minting the tokens. We are creating 100 million tokens upfront.

_mint(msg.sender, 100000000 * 10 ** decimals());

Below is the entire contract code so you can copy it into Remix.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract YourToken is ERC20 {
    constructor() ERC20("YourToken", "YRT") {
    _mint(msg.sender, {max_token_supply} * 10 ** decimals());
    }
}

Step 3: Compile the contract

Click on the Compiler icon on the left, then click on [Compile contract-z1token.sol] (select the file name you just created for your contract).

You should see a green check mark next to the Compiler icon.

Step 4: Deploy the contract

Now that it is compiled, we are ready to deploy the contract to the blockchain and actually create our tokens.

Before we start, make sure your Web3 wallet is connected to ONUS Chain.

Click on the [Deploy] button

In a few seconds, you should see the confirmation message in the bottom part of your Remix window.

Indicating your contract, and your token is now written onto the Blockchain and is ready to go!

Last updated