How to Create Your Own Transferrable Token on the Ethereum Blockchain

·

Learn the fundamentals of Solidity and HardHat while deploying your custom, transferrable token on the Ethereum blockchain. This guide covers everything from setting up your environment to deploying and interacting with your token via MetaMask.

Key Terminology


Setting Up Your Development Environment

Prerequisites

Tools

  1. HardHat: Simplifies contract compilation/deployment.
  2. MetaMask: Crypto wallet for managing accounts and interacting with Ethereum.

👉 Get started with HardHat here


Step-by-Step Token Creation

1. Initialize Your Project

mkdir eth-token && cd eth-token  
npm init -y  

2. Install HardHat

npm install --save-dev hardhat  
npx hardhat  

Select "Create an empty hardhat.config.js" when prompted.

3. Add Dependencies

npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers  

Writing the Smart Contract

Create /contracts/Token.sol and add the following code:

pragma solidity ^0.8.7;  
contract Token {  
    string public name = "CustomToken";  
    string public symbol = "CTK";  
    address public owner;  
    uint public totalSupply = 1000000;  
    mapping(address => uint) balances;  

    constructor() {  
        owner = msg.sender;  
        balances[owner] = totalSupply;  
    }  

    function transfer(address to, uint amount) external {  
        require(balances[msg.sender] >= amount, "Insufficient balance");  
        balances[msg.sender] -= amount;  
        balances[to] += amount;  
    }  

    function balanceOf(address account) external view returns (uint) {  
        return balances[account];  
    }  
}  

Compile the Contract

npx hardhat compile  

Deploying to Ethereum

1. Configure hardhat.config.js

Add your Infura API URL and MetaMask private key:

require('@nomiclabs/hardhat-waffle');  
module.exports = {  
  solidity: "0.8.7",  
  networks: {  
    rinkeby: {  
      url: "YOUR_INFURA_URL",  
      accounts: ["YOUR_PRIVATE_KEY"]  
    }  
  }  
};  

2. Deploy with HardHat

npx hardhat run scripts/deploy.js --network rinkeby  

Save the contract address after deployment.


Adding the Token to MetaMask

  1. Open MetaMask.
  2. Click Add Token > Custom Token.
  3. Paste your contract address—the token symbol and decimals will auto-populate.

👉 Explore advanced token standards like ERC-20


FAQs

Q1: Can I change the token supply after deployment?

A: No, the total supply is fixed at deployment. Modify the totalSupply variable in the contract code and redeploy.

Q2: Why use Rinkeby instead of mainnet?

A: Rinkeby is a testnet—ideal for practice without real ETH costs.

Q3: How do I distribute tokens?

A: Call the transfer() function from the owner’s account to recipient addresses.


Next Steps

Need help? Reach out on Twitter. Happy coding! 🚀