Unichain Docs

Deploy an ERC-20 Contract

Learn how to deploy an ERC-20 contract on Unichain

Deploying an ERC-20 contract on Unichain is as simple as deploying a smart contract. For additional reading, developers should see deploy a smart contract

Summary

Deploy an ERC-20 token contract, minting 1,000,000 tokens to the deployer

Requirements

ETH on Unichain is required, see Funding a Wallet

  1. The guide uses foundry

    for deployments. Install it by running:

    curl -L https://foundry.paradigm.xyz | bash
  2. Add Unichain to your foundry.toml

    [rpc_endpoints]
    unichain = "https://sepolia.unichain.org"
  3. Additionally, an ERC-20 implementation from solmate

    forge install transmissions11/solmate

    Other community implementations are available such as:

Steps

  1. Define the Token Contract

    Most tokens inherit an existing ERC-20 implementation. For this guide, solmate's ERC-20 implementation is used.

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.20;
     
    import {ERC20} from "solmate/tokens/ERC20.sol";
     
    contract ExampleToken is ERC20 {
        constructor() ERC20("ExampleToken", "EXT", 18) {
            _mint(msg.sender, 1_000_000e18);
        }
    }

    In the example, the deployer is minted 1,000,000 EXT tokens. Developers can configure:

    • Token name, i.e. ExampleToken

    • Token symbol, i.e. EXT

    • Token decimal precision, i.e. 18

    • Minting mechanisms

    It is best practice to create tokens with 18 decimals of precision. A significant majority of tokens adhere to this, and most protocols and apps expect this standard.

  2. Deploy the Token

    Deploy the token (smart contract) with foundry:

    forge create src/ExampleToken.sol:ExampleToken \
        --rpc-url unichain \
        --private-key {YourPrivateKey} \
        --etherscan-api-key {EtherscanAPIKey} \
        --verify

    See deploy a smart contract

    for more information

  3. Transferring Tokens (Optional)

    Upon creation of the token, the deployer is the owner of all 1,000,000 tokens. To transfer the tokens, use the transfer function:

    /// @notice Moves `amount` tokens from the caller's account to `to`.
    function transfer(address to, uint256 amount) external returns (bool);

    The transfer function is callable from a block explorer, a web framework, or a backend language such as typescript, python, or rust. To transfer tokens using cast

    :

    cast send {TOKEN_ADDRESS} "transfer(address,uint256)" {RECIPIENT_ADDRESS} {AMOUNT} \
        --rpc-url unichain \
        --private-key {YourPrivateKey}
  4. Create a Trading Pool on Uniswap v4

    This step is also optional, but developers enable trading of their new token on Uniswap v4:

Last updated on

On this page