Skip to content

Instantly share code, notes, and snippets.

@anonymous-research-group
Last active January 20, 2022 20:59
Show Gist options
  • Select an option

  • Save anonymous-research-group/0702ec58a8cf50ae3b7eca762e3ba2cb to your computer and use it in GitHub Desktop.

Select an option

Save anonymous-research-group/0702ec58a8cf50ae3b7eca762e3ba2cb to your computer and use it in GitHub Desktop.

Revisions

  1. anonymous-research-group renamed this gist Dec 7, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. anonymous-research-group created this gist Dec 7, 2020.
    27 changes: 27 additions & 0 deletions BaseToken
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    pragma solidity ^0.5.16;

    import "../openzeppelin-contracts/GSN/Context.sol";
    import "../openzeppelin-contracts/token/ERC20/ERC20.sol";
    import "../openzeppelin-contracts/token/ERC20/ERC20Detailed.sol";

    import "../openzeppelin-contracts/math/SafeMath.sol";


    contract BaseToken is Context, ERC20, ERC20Detailed {
    uint256 tokenPrice = 100 wei;
    using SafeMath for uint256;
    using SafeMath for uint;

    constructor () public payable ERC20Detailed("BaseToken", "BT", 18) {
    _mint(_msgSender(), SafeMath.div(msg.value, tokenPrice));
    }

    function buyTokens() public payable {
    _mint(_msgSender(), SafeMath.div(msg.value, tokenPrice));
    }

    function sellTokens(uint256 amount) public {
    _burn(_msgSender(), amount);
    address(msg.sender).transfer( SafeMath.mul(amount, tokenPrice));
    }
    }