Skip to content

Commit

Permalink
Create pi_network_module_2: Token.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 28, 2024
1 parent 274dffd commit d628c60
Showing 1 changed file with 39 additions and 0 deletions.
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);
}
}

0 comments on commit d628c60

Please sign in to comment.