Happy Cuan Airdrop
Back to overview

How to Deploy a Token on Remix Using Solidity

This tutorial will guide you through the process of deploying a custom ERC-20 token on the Remix IDE. The token will be created using the provided Solidity code, and you will customize the constructor to include your token's name, symbol, and supply.


## Prerequisites

1. Remix IDE: Access the Remix IDE.

2. Metamask: Install and set up Metamask to interact with the EVM.

3. Test ETH: Obtain test ETH (e.g., from a faucet) for deploying the contract on a testnet.


## Step 1: Write the Smart Contract

1. Open the Remix IDE.

2. Create a new file named MyToken.sol.

3. Copy and paste the following code into the file:


// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.2;

contract ERC20 {
    mapping(address => uint256) public balances;
    mapping(address => mapping(address => uint256)) public allowed;

    uint256 public totalSupply;
    string public name;
    string public symbol;
    uint256 public decimals = 18;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    constructor(string memory _name, string memory _symbol, uint256 _supply) {
        name = _name;
        symbol = _symbol;
        totalSupply = _supply * (10 ** decimals);
        balances[msg.sender] = totalSupply;
    }

    function transfer(address to, uint256 value) public {
        require(balances[msg.sender] >= value, "Insufficient balance");
        balances[msg.sender] -= value;
        balances[to] += value;
        emit Transfer(msg.sender, to, value);
    }

    function approve(address spender, uint256 value) public {
        allowed[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
    }

    function transferFrom(address from, address to, uint256 value) public {
        require(balances[from] >= value, "Insufficient balance");
        require(allowed[from][msg.sender] >= value, "Allowance exceeded");
        balances[from] -= value;
        balances[to] += value;
        allowed[from][msg.sender] -= value;
        emit Transfer(from, to, value);
    }

    function balanceOf(address owner) public view returns (uint256) {
        return balances[owner];
    }

    function allowance(address owner, address spender) public view returns (uint256) {
        return allowed[owner][spender];
    }
}


## Step 2: Compile the Contract

1. Go to the Solidity Compiler tab in Remix.

2. Select the appropriate compiler version (e.g., 0.8.2).

3. Click Compile MyToken.sol.

4. Ensure there are no errors in the compilation process.


## Step 3: Deploy the Contract

1. Go to the Deploy & Run Transactions tab in Remix.

2. Select the environment (e.g., Injected Web3 to connect to Metamask).

3. Choose the MyToken contract from the dropdown menu.

  1. Fill with your token name, token code, and the supply.

5. Click Deploy.

6. Confirm the transaction in Metamask.


## Step 4: Interact with the Token

1. Once deployed, you can interact with the token using the functions provided in the contract:

- transfer: Send tokens to another address.

- balanceOf: Check the balance of an address.

- approve and transferFrom: Allow another address to spend tokens on your behalf.

2. Use the Remix interface to call these functions by entering the required parameters and clicking the respective buttons.


## Conclusion

You have successfully deployed your own ERC-20 token using Remix IDE. You can now explore further functionalities, such as integrating your token with decentralized applications or listing it on exchanges. Happy coding!

Telegram

Happy Cuan Airdrop is the Quickest way to discover legitimate cryptocurrency airdrops in your area!

Join our Telegram community.

Join now
I’m new to airdrops. How do I start?
How can I find legit airdrops?
No worries! Join our Telegram group, and we'll share the latest airdrop opportunities!
Our experts will help you find the best and safest airdrops.

Start

Your

Journey

v1.2.1 (139)