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_) {
23 name = name_;
24 symbol = symbol_;
25 owner = msg.sender;
26 uint256 supply = initialSupply_ * 10 ** decimals;
27 totalSupply = supply;
28 balanceOf[msg.sender] = supply;
29 emit Transfer(address(0), msg.sender, supply);
30 }
31 
32 function transfer(address to, uint256 value) external returns (bool) {
33 _transfer(msg.sender, to, value);
34 return true;
35 }
36 
37 function approve(address spender, uint256 value) external returns (bool) {
38 allowance[msg.sender][spender] = value;
39 emit Approval(msg.sender, spender, value);
40 return true;
41 }
42 
43 function transferFrom(address from, address to, uint256 value) external returns (bool) {
44 uint256 allowed = allowance[from][msg.sender];
45 require(allowed >= value, "ALLOWANCE");
46 if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - value;
47 _transfer(from, to, value);
48 return true;
49 }
50 
51 function mint(address to, uint256 amount) external onlyOwner {
52 totalSupply += amount;
53 balanceOf[to] += amount;
54 emit Transfer(address(0), to, amount);
55 }
56 
57 function burn(uint256 amount) external {
58 require(balanceOf[msg.sender] >= amount, "BALANCE");
59 balanceOf[msg.sender] -= amount;
60 totalSupply -= amount;
61 emit Transfer(msg.sender, address(0), amount);
62 }
63 
64 function _transfer(address from, address to, uint256 value) internal {
65 require(to != address(0), "ZERO_ADDR");
66 require(balanceOf[from] >= value, "BALANCE");
67 balanceOf[from] -= value;
68 balanceOf[to] += value;
69 emit Transfer(from, to, value);
70 }
71}
DevStation
Loading console…