Advertisement
Guest User

Stuf6756576

a guest
Mar 31st, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.5.11;
  2. contract InheritanceModifierExample {
  3.  
  4.  mapping(address => uint) public tokenBalance;
  5.  
  6.  address owner;
  7.  
  8.  uint tokenPrice = 1 ether;
  9.  
  10.  constructor() public {
  11.  owner = msg.sender;
  12.  tokenBalance[owner] = 100;
  13.  }
  14.  
  15.  function createNewToken() public {
  16.  require(msg.sender == owner, "You are not allowed");
  17.  tokenBalance[owner]++;
  18.  }
  19.  
  20.  function burnToken() public {
  21.  require(msg.sender == owner, "You are not allowed");
  22.  tokenBalance[owner]--;
  23.  }
  24.  
  25.  function purchaseToken() public payable {
  26.  require((tokenBalance[owner] * tokenPrice) / msg.value > 0, "not enoug
  27. h tokens");
  28.  tokenBalance[owner] -= msg.value / tokenPrice;
  29.  tokenBalance[msg.sender] += msg.value / tokenPrice;
  30.  }
  31.  
  32.  function sendToken(address _to, uint _amount) public {
  33.  require(tokenBalance[msg.sender] >= _amount, "Not enough tokens");
  34.  assert(tokenBalance[_to] + _amount >= tokenBalance[_to]);
  35.  assert(tokenBalance[msg.sender] - _amount <= tokenBalance[msg.sender])
  36. ;
  37.  tokenBalance[msg.sender] -= _amount;
  38.  tokenBalance[_to] += _amount;
  39.  }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement