-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNomadToken.sol
More file actions
79 lines (66 loc) · 2.49 KB
/
Copy pathNomadToken.sol
File metadata and controls
79 lines (66 loc) · 2.49 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract NomadToken {
string public name;
string public symbol;
uint8 public constant decimals = 18;
uint256 public totalSupply;
address public owner;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
modifier onlyOwner() {
require(msg.sender == owner, "Only owner");
_;
}
constructor(
string memory tokenName,
string memory tokenSymbol,
uint256 initialSupply,
address recipient
) {
name = tokenName;
symbol = tokenSymbol;
owner = msg.sender;
_mint(recipient, initialSupply);
}
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint256 amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
uint256 currentAllowance = allowance[from][msg.sender];
require(currentAllowance >= amount, "Allowance exceeded");
allowance[from][msg.sender] = currentAllowance - amount;
_transfer(from, to, amount);
return true;
}
function mint(address to, uint256 amount) external onlyOwner {
_mint(to, amount);
}
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Zero owner");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function _transfer(address from, address to, uint256 amount) internal {
require(to != address(0), "Zero recipient");
require(balanceOf[from] >= amount, "Insufficient balance");
balanceOf[from] -= amount;
balanceOf[to] += amount;
emit Transfer(from, to, amount);
}
function _mint(address to, uint256 amount) internal {
require(to != address(0), "Zero recipient");
totalSupply += amount;
balanceOf[to] += amount;
emit Transfer(address(0), to, amount);
}
}