Created
July 8, 2022 16:32
-
-
Save p14041999/e3c33dbc536d0486d1944f7af0025dd8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.10+commit.fc410830.js&optimize=false&runs=200&gist=
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: UNLICENSED | |
| pragma solidity ^0.8.10; | |
| // should store balance | |
| // can be transferred | |
| // generation of token | |
| // CASE1: I WANT TO TRANSFER FROM MY ACCOUNT TO SOMEONE ELSE ✅ | |
| // IF WE ALLOW CASE 2 | |
| // CASE2: I WANT TO TRANSFER FROM ANOTHER ACCOUNT TO SOMEONE ELSE / MY ACCOUNT ✅ | |
| // _allowance[user][spender] | |
| contract Token{ | |
| uint _totalSupply = 0; | |
| mapping(address=>uint) _balances; | |
| mapping(address=>mapping(address=>uint)) _allowance; | |
| address owner; | |
| modifier onlyOwner(){ | |
| require(msg.sender == owner,"ERROR: OWNER ONLY"); | |
| _; | |
| } | |
| event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
| event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
| constructor(){ | |
| owner = msg.sender; | |
| } | |
| function name() public pure returns (string memory){ | |
| return "Indian Rupee"; | |
| } | |
| function symbol() public pure returns (string memory){ | |
| return "INR"; | |
| } | |
| function decimals() public pure returns (uint){ | |
| return 0; | |
| } | |
| function totalSupply() public view returns (uint){ | |
| return _totalSupply; | |
| } | |
| // CASE 1 | |
| function transfer(address to,uint amount) public virtual { | |
| // msg.sender => FROM ADDRESS | |
| _transfer(msg.sender,to,amount); | |
| } | |
| // CASE 2 | |
| // -> approve | |
| function approve(address spender, uint amount) public virtual{ | |
| _allowance[msg.sender][spender] = amount; | |
| emit Approval(msg.sender,spender,amount); | |
| } | |
| // -> allowance | |
| function allowance(address user,address spender) public view virtual returns(uint){ | |
| return _allowance[user][spender]; | |
| } | |
| // -> tranferFrom | |
| function transferFrom(address from,address to, uint amount) public virtual{ | |
| require(_allowance[from][msg.sender] >= amount, "ERROR: _allowance Exceeds"); | |
| _transfer(from,to,amount); | |
| _allowance[from][msg.sender] -= amount; | |
| } | |
| function _transfer(address from, address to,uint amount) internal virtual{ | |
| // TODO: TRANSFER TOKEN FROM ONE ACCOUNT TO ANOTHER | |
| _balances[from] -= amount; | |
| _balances[to] += amount; | |
| emit Transfer(from,to,amount); | |
| } | |
| function balanceOf(address user) public view virtual returns(uint){ | |
| return _balances[user]; | |
| } | |
| function _mint(address receiver, uint amount) public onlyOwner virtual { | |
| // TODO: INCREASE NUMBER OF TOTAL TOKENS | |
| _balances[receiver] += amount; | |
| _totalSupply += amount; | |
| } | |
| function _burn(uint amount) public virtual { | |
| // TODO: DECREASE NUMBER OF TOTAL TOKENS | |
| _balances[msg.sender] -= amount; | |
| _totalSupply -= amount; | |
| } | |
| } | |
| // Owner => 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 (D) -> 100990 | |
| // Sanchita => 0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB | |
| // Amiya => 0x1aE0EA34a72D944a8C7603FfB3eC30a6669E454C -> 10 | |
| // Bigbazzar => 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment