Created
February 1, 2021 11:09
-
-
Save 0xAnon101/12d2eae99e9f43436e328de12ad2feeb to your computer and use it in GitHub Desktop.
send/mint/transfer currency
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: GPL-3.0 | |
| pragma solidity >=0.5.0 <0.9.0; | |
| import "github/OpenZeppelin/openzeppelin-contracts/contracts/math/SafeMath.sol"; | |
| contract Scoin { | |
| using SafeMath for uint256; | |
| address public minter; | |
| mapping (address => uint256) public balances; | |
| event Sent(address indexed from , address indexed to, uint256 amount, uint256 sBalance, uint256 rBalance); | |
| event OwnerChanged(address indexed from , address indexed to); | |
| constructor() public { | |
| minter = msg.sender; | |
| emit OwnerChanged(address(0), minter); | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == minter); | |
| _; | |
| } | |
| // only creator can mint the token | |
| function mint(address _receiver, uint256 _amount) public onlyOwner { | |
| uint256 currentBalance = balances[_receiver].add(_amount); | |
| require(currentBalance >= balances[_receiver], "out of bound"); | |
| balances[_receiver] = currentBalance; | |
| } | |
| // send amount of coins from any caller to an address | |
| function send(address _receiver, uint256 _amount) public { | |
| require(balances[msg.sender] >= _amount, "Insufficient balance"); | |
| balances[msg.sender] = balances[msg.sender].sub(_amount); | |
| balances[_receiver] = balances[_receiver].add(_amount); | |
| emit Sent(msg.sender, _receiver, _amount, balances[msg.sender], balances[_receiver]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment