-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract.sol
More file actions
41 lines (28 loc) · 1.1 KB
/
Copy pathcontract.sol
File metadata and controls
41 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SimpleTokenTransfer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleTokenTransfer {
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
// Events
event Transfer(address indexed from, address indexed to, uint256 value);
constructor(uint256 initialSupply) {
_totalSupply = initialSupply;
_balances[msg.sender] = initialSupply;
emit Transfer(address(0), msg.sender, initialSupply);
}
function totalSupply() external view returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) external view returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 value) external returns (bool) {
require(to != address(0), "Transfer to the zero address");
require(_balances[msg.sender] >= value, "Insufficient balance");
_balances[msg.sender] -= value;
_balances[to] += value;
emit Transfer(msg.sender, to, value);
return true;
}
}