generated from Refloow/BEP20-Smart-Contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Token.sol
40 lines (34 loc) · 1.18 KB
/
Token.sol
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
// Current Version of solidity
pragma solidity ^0.8.4;
// Main coin information
contract Token {
// Initialize addresses mapping
mapping(address => uint) public balances;
// Total supply (in this case 1000 tokens)
uint public totalSupply = 1000 * 10 ** 18;
// Tokens Name
string public name = "My Token";
// Tokens Symbol
string public symbol = "MTK";
// Total Decimals (max 18)
uint public decimals = 18;
// Transfers
event Transfer(address indexed from, address indexed to, uint value);
// Event executed only ones uppon deploying the contract
constructor() {
// Give all created tokens to adress that deployed the contract
balances[msg.sender] = totalSupply;
}
// Check balances
function balanceOf(address owner) public view returns(uint) {
return balances[owner];
}
// Transfering coins function
function transfer(address to, uint value) public returns(bool) {
require(balanceOf(msg.sender) >= value, 'Insufficient balance');
balances[to] += value;
balances[msg.sender] -= value;
emit Transfer(msg.sender, to, value);
return true;
}
}