-
Notifications
You must be signed in to change notification settings - Fork 0
/
contrato basico de tokens em solidity
77 lines (55 loc) · 2.24 KB
/
contrato basico de tokens em solidity
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract tokenCR {
string _name = "token CR";
string _symbol = "sith";
uint8 _decimals = 8;
uint _totalsupply ;
mapping (address => uint) _balances ;
mapping (address => mapping (address => uint )) _allowance;
event Transfer (address indexed _from , address indexed _to , uint256 _value);
event approval (address indexed _owner , address indexed _spender , uint256 _value);
constructor (){
_totalsupply = 100_000 * 10 ** _decimals ;
_balances [msg.sender] = _totalsupply ;
}
function name () public view returns ( string memory){
return _name ;
}
function symbol () public view returns (string memory){
return _symbol ;
}
function decimals () public view returns (uint8){
return _decimals;
}
function totalsupply () public view returns (uint){
return _totalsupply ;
}
function balanceOf (address _owner) public view returns (uint){
return _balances[_owner];
}
function transfer (address _to , uint _value ) public returns (bool){
require(_balances [msg.sender] >= _value, "saldo insuficiente");
_balances [msg.sender] = _balances [msg.sender] - _value ;
_balances [_to] = _balances [_to] + _value ;
emit Transfer(msg.sender, _to, _value);
return true ;
}
function tranferfrom (address _from , address _to , uint value ) public returns (bool){
require(_balances [_from] >= value , "saldo insuficiente");
require(allowance(_from , msg.sender) >= value , unicode"sem autorizaçao");
_balances [_from] = _balances [_from] - value ;
_balances [_to] = _balances [_to] + value ;
_allowance [_from][msg.sender] = _allowance [_from][msg.sender] - value ;
emit Transfer(_from, _to, value);
return true;
}
function allowance (address _owner , address _spender) public view returns (uint){
return _allowance [_owner][_spender];
}
function approve (address _spender , uint _value) public returns (bool){
_allowance [ msg.sender][_spender] = _value ;
emit approval(msg.sender, _spender, _value);
return true ;
}
}