-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create pi_network_module_2: Token.sol
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...pi_network/features/pi_network_smart_contract_architecture/pi_network_module_2: Token.sol
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol"; | ||
|
||
contract Token { | ||
using SafeERC20 for address; | ||
|
||
// Mapping of token balances | ||
mapping (address => uint256) public balances; | ||
|
||
// Total supply of tokens | ||
uint256 public totalSupply; | ||
|
||
// Event emitted when tokens are transferred | ||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
|
||
// Function to transfer tokens | ||
function transfer(address _to, uint256 _value) public { | ||
require(balances[msg.sender] >= _value, "Insufficient balance"); | ||
balances[msg.sender] -= _value; | ||
balances[_to] += _value; | ||
emit Transfer(msg.sender, _to, _value); | ||
} | ||
|
||
// Function to mint new tokens | ||
function mint(address _to, uint256 _value) public onlyAdmin { | ||
totalSupply += _value; | ||
balances[_to] += _value; | ||
emit Transfer(address(0), _to, _value); | ||
} | ||
|
||
// Function to burn tokens | ||
function burn(uint256 _value) public { | ||
require(balances[msg.sender] >= _value, "Insufficient balance"); | ||
balances[msg.sender] -= _value; | ||
totalSupply -= _value; | ||
emit Transfer(msg.sender, address(0), _value); | ||
} | ||
} |