Last active
March 26, 2024 13:23
-
-
Save hashcott/1686dc9952c189d6f1615fb999036a3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| pragma solidity 0.8.25; | |
| contract Token { | |
| mapping (address => uint) public balances; | |
| mapping (address => mapping (address => uint)) public allowances; | |
| uint public totalSupply; | |
| address public foundation; | |
| string public name = "LUAGA"; | |
| constructor() { | |
| foundation = msg.sender; | |
| totalSupply = 1000000000; | |
| balances[foundation] = totalSupply; | |
| } | |
| function transfer(address _to, uint _value) public { | |
| require(balances[msg.sender] >= _value); | |
| balances[_to] += _value; | |
| balances[msg.sender] -= _value; | |
| } | |
| function balanceOf( address _addr) public view returns (uint) { | |
| return balances[_addr]; | |
| } | |
| // anh X cấp cho anh Y1,y2,y3... số tiền là Z1, z2, z3 để tiêu dùng | |
| function approve(address _spender, uint _value) public { | |
| // check số dư phải lớn hơn | |
| require(balances[msg.sender] >= _value); | |
| // cấp tín dụng cho anh spender | |
| allowances[msg.sender][_spender] = _value; | |
| // giảm số dư của người dùng | |
| // balances[msg.sender] -= _value; | |
| } | |
| function transferFrom(address _from, address _to, uint _value) public { | |
| // số tiền tín tín dụng còn không ? | |
| require(allowances[_from][msg.sender] >= _value); | |
| // check tài khoản thực | |
| require(balances[_from] >= _value); | |
| // chuyển tiền tới _to | |
| balances[_to] += _value; | |
| // giảm số tín dụng | |
| allowances[_from][msg.sender] -= _value; | |
| // cập nhật lại số dư của chủ cấp tin dụng | |
| balances[_from] -= _value; | |
| } | |
| function allowance(address _from) public view returns (uint) { | |
| return allowances[_from][msg.sender]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment