Skip to content

Instantly share code, notes, and snippets.

@OdionOseiwe
Last active August 6, 2022 15:43
Show Gist options
  • Select an option

  • Save OdionOseiwe/6905c8e72e09755edbadd6b509735199 to your computer and use it in GitHub Desktop.

Select an option

Save OdionOseiwe/6905c8e72e09755edbadd6b509735199 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract tokenContract{
//have total supply
//transferrable
//name
//symbol
//decimal
//user balance
//burnable
/// state variables ///
uint totalSupply = 10000;
string name = "ENGERY";
string symbol = "EGY";
uint decimal = 1e18;
uint circulatingSupply;
address owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner(){
// require(msg.sender == owner, "not owner");
if(msg.sender != owner) {
revert OnlyOwner();
}
_;
}
/// Get out! only owner can call this function
error OnlyOwner();
event minted(address indexed _address, uint _amount);
event transFrom(address indexed _from, address indexed _to, uint _amount);
mapping(address => uint) Balances;
function ReName() external view returns(string memory){
return name;
}
function ReSymbol() external view returns(string memory){
return symbol;
}
function ReDecimal() external view returns(uint){
return decimal;
}
function ReCirculatingSupply() external view returns(uint){
return circulatingSupply;
}
/// @dev create a mint function
function mint(uint _amount, address _address) external onlyOwner{
require(_address != address(0), "address zero not allowed");
//add amount to circSupply
require(_amount <= totalSupply, "insufficient funds");
circulatingSupply = circulatingSupply + _amount;
// made show totAL supply remains constant
uint value = _amount * decimal;
Balances[_address] = value;
emit minted(_address, _amount);
}
/// @dev create a transfer function
function transfer(address _address , uint _amount) external {
require(_address != address(0), "not this address");
require(Balances[msg.sender] >= _amount , "insufficient funds");
uint transferable = amountofBurn( _amount);
Balances[msg.sender] = Balances[msg.sender] - _amount;
Balances[_address] = Balances[_address] + transferable;
}
/// @dev calculate burn
function circulateBurn(uint _amount) public pure returns(uint){
return (_amount * 10)/100;
}
/// @dev return amount to be transfered
function amountofBurn(uint _amount) internal returns(uint ReAmount){
circulatingSupply = circulatingSupply - circulateBurn(_amount);
ReAmount = _amount - circulateBurn(_amount);
}
/// @dev return balance for an address
function ReBalance(address _address) external view returns(uint){
return Balances[_address];
}
/// @dev another section
//we are giving the someone permission to transfer a token
// owner(sugar daddy) ==> reciever() ==> amount
mapping(address => mapping(address => uint)) Dtransfer;
function transferFrom(address _from , address _to, uint _amount) external {
require(_to != address(0), "not this address");
require(_to == msg.sender, "not allowed");
require(Dtransfer[_from][msg.sender] >= _amount, "not you");
uint transferable = amountofBurn( _amount);
Dtransfer[_from][msg.sender] = Dtransfer[_from][msg.sender] - _amount;
Balances[_from] = Balances[_from] - _amount;
Balances[_to] = Balances[_to] + transferable;
emit transFrom(_from , _to , _amount );
}
function approve(address _spender, uint _amount) external {
require(_spender != address(0), "not this address");
uint ownerAmount = Balances[msg.sender];
require(ownerAmount >= _amount, "thief");
Dtransfer[msg.sender][_spender] = Dtransfer[msg.sender][_spender] + _amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment