DevStation / LaunchKit / Templates / SimpleERC20

SimpleERC20

A standard ERC-20 fungible token with configurable name, symbol, total supply, owner-only minting, and public burning.

Deploy This Template
SimpleERC20.sol
solidity
1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.20;
3 
4contract SimpleERC20 {
5 string public name;
6 string public symbol;
7 uint8 public constant decimals = 18;
8 uint256 public totalSupply;
9 address public owner;
10 
11 mapping(address => uint256) public balanceOf;
12 mapping(address => mapping(address => uint256)) public allowance;
13 
14 event Transfer(address indexed from, address indexed to, uint256 value);
15 event Approval(address indexed owner, address indexed spender, uint256 value);
16 
17 modifier onlyOwner() {
18 require(msg.sender == owner, "NOT_OWNER");
19 _;
20 }
21 
22 constructor(string memory name_, string memory symbol_, uint256 initialSupply_, address initialOwner_) {
23 require(initialOwner_ != address(0), "ZERO_OWNER");
24 name = name_;
25 symbol = symbol_;
26 owner = initialOwner_;
27 uint256 supply = initialSupply_ * 10 ** decimals;
28 totalSupply = supply;
29 balanceOf[initialOwner_] = supply;
30 emit Transfer(address(0), initialOwner_, supply);
31 }
32 
33 function transfer(address to, uint256 value) external returns (bool) {
34 _transfer(msg.sender, to, value);
35 return true;
36 }
37 
38 function approve(address spender, uint256 value) external returns (bool) {
39 allowance[msg.sender][spender] = value;
40 emit Approval(msg.sender, spender, value);
41 return true;
42 }
43 
44 function transferFrom(address from, address to, uint256 value) external returns (bool) {
45 uint256 allowed = allowance[from][msg.sender];
46 require(allowed >= value, "ALLOWANCE");
47 if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - value;
48 _transfer(from, to, value);
49 return true;
50 }
51 
52 function mint(address to, uint256 amount) external onlyOwner {
53 totalSupply += amount;
54 balanceOf[to] += amount;
55 emit Transfer(address(0), to, amount);
56 }
57 
58 function burn(uint256 amount) external {
59 require(balanceOf[msg.sender] >= amount, "BALANCE");
60 balanceOf[msg.sender] -= amount;
61 totalSupply -= amount;
62 emit Transfer(msg.sender, address(0), amount);
63 }
64 
65 function _transfer(address from, address to, uint256 value) internal {
66 require(to != address(0), "ZERO_ADDR");
67 require(balanceOf[from] >= value, "BALANCE");
68 balanceOf[from] -= value;
69 balanceOf[to] += value;
70 emit Transfer(from, to, value);
71 }
72}
DevStation
Loading console…