Skip to content

Instantly share code, notes, and snippets.

@Napcalx
Last active March 24, 2024 14:21
Show Gist options
  • Save Napcalx/6040403ee4e7f896d0ada7ce28e97c26 to your computer and use it in GitHub Desktop.
Save Napcalx/6040403ee4e7f896d0ada7ce28e97c26 to your computer and use it in GitHub Desktop.
Wazuh Token
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;
// A token that can be transfered from one person to another
// It should have a name
// It should have maximum supply
// It should have initial supply
// Total supply
// symbol
// owner
// balanceof
// allowance
// minting
// burnable
// event
contract Wazuh{
string _name;
string _symbol;
uint constant DECIMAL = 18;
uint _totalSupply;
// return the balance of user which is the address
mapping (address => uint) _balance;
// owner => spender => value
mapping (address => mapping(address => uint)) _allowance;
event Transfer(address from, address to, uint value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Minted(address to, uint value);
constructor (string memory name_, string memory symb_) {
_name = name_;
_symbol = symb_;
}
function name () public view returns (string memory) {
return _name;
}
function symbol () public view returns (string memory) {
return _symbol;
}
function decimals () public pure returns (uint) {
return DECIMAL;
}
function totalSupply () public view returns (uint) {
return _totalSupply;
}
function balanceOf (address _owner) public view returns (uint256 balance ) {
return _balance[_owner];
}
function transfer (address _to, uint256 _value) public returns (bool success) {
require (_to != address(0), "transfer to address Zero not allowed");
require (_value > 0, "increase value");
require (balanceOf(msg.sender) >= _value, "insufficient funds");
_balance[msg.sender] -= _value;
_balance[_to] += _value;
success = true;
emit Transfer(msg.sender, _to, _value);
}
function transferFrom (address _from, address _to, uint256 _value) public returns (bool success) {
require (_to != address(0), "transfer to address Zero not allowed");
require (_value > 0, "increase value");
require (balanceOf(_from) >= _value, "insufficient funds");
require (allowance(_from, _to) <= _value, "insufficient allowance");
_allowance[_from][_to] -= _value;
_balance[_from] -= _value;
_balance[_to] += _value;
success = true;
emit Transfer(_from, _to, _value);
}
function approve(address _spender, uint256 _value) public returns (bool success) {
_allowance[msg.sender][_spender] = _value;
success = true;
emit Approval(msg.sender, _spender, _value);
}
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return _allowance[_owner][_spender];
}
function mint (address _to, uint value) external {
require (_to != address(0), "trasnfer to address Zero not allowed");
_totalSupply += value;
_balance[_to] += value;
emit Minted(_to, value);
}
function burn(uint value, address target) external {
require(balanceOf(msg.sender) >= value, "insufficient funds");
_balance[msg.sender] -= value;
uint burnValue = (value * 90) / 100;
_totalSupply -= burnValue;
_balance[target] = value - burnValue;
}
}
0x6D9bb552f5fa5f180Bb5C8c31ce877365088427D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment