Blockchain 6 min read

Build and Deploy a Custom ERC20 Token on a Local Ethereum Chain with Truffle and OpenZeppelin

This step‑by‑step guide shows how to set up a Mac development environment, create a Truffle project, install OpenZeppelin, write and compile a simple ERC20 token contract, deploy it to a Ganache private Ethereum network, and interact with it via MetaMask.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
Build and Deploy a Custom ERC20 Token on a Local Ethereum Chain with Truffle and OpenZeppelin

Prepare Development Environment (Mac)

Tools required: Node.js (v9.11.1) and npm (v5.6.0), Truffle (v4.1.5, Solidity 0.4.21), Ganache (v1.1.0).

Create a Truffle Project

Initialize with the tutorial token unbox: truffle unbox tutorialtoken The generated directory follows the standard Truffle layout: contracts/ – Solidity contract files (*.sol) migrations/ – Deployment scripts test/ – Test scripts truffle.js – Truffle configuration file

Install OpenZeppelin Contracts

npm install zeppelin-solidity

Write ERC20 Smart Contract

Create contracts/FakeToken.sol with the following content:

pragma solidity ^0.4.17;

import 'zeppelin-solidity/contracts/token/ERC20/StandardToken.sol';

contract FakeToken is StandardToken {
    string public name = 'FakeToken';
    string public symbol = 'TT';
    uint8 public decimals = 2;
    uint public INITIAL_SUPPLY = 12000;

    function FakeToken() public {
        totalSupply_ = INITIAL_SUPPLY;
        balances[msg.sender] = INITIAL_SUPPLY;
    }
}

Compile the Contract

truffle compile

Typical output shows compilation of FakeToken.sol and Migrations.sol and writes artifacts to ./build/contracts. Warnings about missing visibility can be ignored for this tutorial.

Deploy the Contract

Create migrations/2_deploy_contracts.js:

var FakeToken = artifacts.require("FakeToken");

module.exports = function(deployer) {
    deployer.deploy(FakeToken);
};

Start Ganache (default RPC port 7545) and run: truffle migrate The migration creates the contract address and four transactions (four blocks).

Ganache deployment screenshot
Ganache deployment screenshot

Interact via Front‑End and MetaMask

Update the front‑end RPC endpoint from port 9545 to Ganache’s 7545:

App.web3Provider = new Web3.providers.HttpProvider('http://127.0.0.1:7545');

Replace references to TutorialToken.json with FakeToken.json in the UI scripts.

Configure MetaMask to connect to the local Ganache network and import the generated accounts. The first account holds the initial token supply.

Start the local HTTP server: npm run dev Test token transfer:

Select the first MetaMask account and refresh the page.

Enter the second account’s address in the “Recipient” field.

Enter a transfer amount (decimals = 2, so the amount is truncated to two decimal places).

Click “Transfer” and confirm the transaction in the MetaMask popup.

Ganache shows a new transaction and the second account receives the tokens.

MetaMask transfer confirmation
MetaMask transfer confirmation

To add the token to MetaMask:

Open MetaMask, go to the “TOKENS” tab, and click “Add Token”.

Enter the contract address displayed in Ganache.

MetaMask automatically fills in the token symbol and decimals.

Confirm to finish.

MetaMask add token screen
MetaMask add token screen

The newly created ERC20 token is fully functional on the local Ethereum network and visible in the MetaMask wallet.

Reference: http://truffleframework.com/tutorials/robust-smart-contracts-with-openzeppelin

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

EthereumTruffleERC20GanacheMetaMaskOpenZeppelin
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.