ERC-20 Tutorial
Overview
The ERC-20 standard is the foundational specification for fungible tokens across Ethereum and EVM-compatible networks. A fungible token represents interchangeable units of value, meaning every token unit is identical to another. This property makes ERC-20 the preferred standard for digital currencies, financial instruments, and tokenized commodities.
In the context of the Watr Network, ERC-20 can be used to represent standardized commodity units such as metals, energy credits, or carbon offsets. For example:
- 1 COPT token = 1 kilogram of Copper
- Each token is uniform and exchangeable
- Supply can represent real-world reserves, vaulted inventory, or synthetic exposure depending on system design
This tutorial demonstrates how to:
- Implement an ERC-20 token using OpenZeppelin
- Deploy the contract
- Mint new commodity units
- Transfer ownership of tokens
- Query total supply and balances
- Understand how this standard applies to commodity tokenization systems
We will use OpenZeppelin Contracts, the industry-standard audited library for secure smart contract development.
Install Dependencies
npm install --save-dev hardhat
npm install @openzeppelin/contracts
CopperToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract CopperToken is ERC20, Ownable {
constructor() ERC20("Copper Token", "COPT") {}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
function burn(address from, uint256 amount) public onlyOwner {
_burn(from, amount);
}
}
Deploy Script
const hre = require("hardhat");
async function main() {
const Copper = await hre.ethers.getContractFactory("CopperToken");
const copper = await Copper.deploy();
await copper.waitForDeployment();
console.log("CopperToken deployed to:", await copper.getAddress());
}
main();
Interaction Scripts
Mint
await Copper.mint("RECIPIENT_ADDRESS", hre.ethers.parseUnits("100", 18));
Transfer
await Copper.transfer("RECIPIENT_ADDRESS", hre.ethers.parseUnits("10", 18));
Total Supply
const totalSupply = await Copper.totalSupply();
Balance Of
const balance = await Copper.balanceOf("WALLET_ADDRESS");
When to Use ERC-20
ERC-20 is ideal when:
- The asset is fully fungible
- All units are identical
- A single commodity is represented per contract
- Financial composability (DeFi integrations) is required
Typical commodity examples:
- Copper
- Silver
- Aluminum
- Gold-backed tokens