Build and Deploy Your Own ERC-20 Token
| Feature | Description |
|---|---|
| Token Name | Your custom cryptocurrency name |
| Token Symbol | 3-5 letter ticker (e.g., BTC, ETH) |
| Total Supply | Fixed supply minted at deployment |
| Decimals | 18 (standard for most tokens) |
| Transfer | Send tokens to any address |
| Approve/TransferFrom | Allow others to spend your tokens |
Decide on your token's properties:
MyToken.sol// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor(
string memory name,
string memory symbol,
uint256 initialSupply
) ERC20(name, symbol) {
_mint(msg.sender, initialSupply * 10**decimals());
}
}
What this does:
0.8.20"Your Token Name""SYM"1000000You should now see your token balance!
Send tokens to a classmate:
transfer function// To send 100 tokens:
transfer("0x...", 100000000000000000000)
| Function | Purpose | Gas |
|---|---|---|
name() | Returns token name | Free (view) |
symbol() | Returns ticker symbol | Free (view) |
decimals() | Returns decimal places (18) | Free (view) |
totalSupply() | Returns total tokens | Free (view) |
balanceOf(address) | Returns balance of address | Free (view) |
transfer(to, amount) | Send tokens | ~65,000 |
approve(spender, amount) | Allow spending | ~45,000 |
transferFrom(from, to, amount) | Spend approved tokens | ~65,000 |
Want to go further? Try adding:
| Question | Answer |
|---|---|
| PROBLEM | Create programmable digital money |
| INCENTIVES | Holders want price appreciation, creators want utility |
| BENEFITS/COSTS | Permissionless creation; oversupply of tokens |
| FAILURE MODE | Rug pulls, worthless tokens, scams |
| DESIGN CHOICES | Fixed vs inflationary supply, governance rights |
| ALTERNATIVES | Traditional loyalty points, gift cards |
Ready for more? Explore the Token Economy semester project to add governance, vesting, and staking to your token!