I got 2 problem when i follow instruction. Here my contract file:

pragma solidity ^0.5.0;

import "./DappToken.sol";

contract DappTokenSale {
    address admin;
    DappToken public tokenContract;
    uint256 public tokenPrice;
    uint256 public tokensSold;

    event Sell(address _buyer, uint256 _amount);

    constructor (DappToken _tokenContract, uint256 _tokenPrice) public {
        admin = msg.sender;
        tokenContract = _tokenContract;
        tokenPrice = _tokenPrice; 

    function multiply (uint x, uint y) internal pure returns (uint z) {
        require(y == 0 || (z = x * y) / y == x);

    function buyTokens (uint256 _numberOfTokens) public payable {
        require (msg.value == multiply(_numberOfTokens, tokenPrice));
        require (tokenContract.balanceOf(address(this)) >= _numberOfTokens);
        require (tokenContract.transfer(msg.sender, _numberOfTokens));

        tokensSold += _numberOfTokens;
        emit Sell(msg.sender, _numberOfTokens);

    function endSale () public {
        require (msg.value == admin);
        require (tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));

and the cmd said:

enter image description here

How to fix this ??


On the first error, msg.value should be msg.sender. On the second error, you need to specify address payable admin; on declaration.

  • The both problem seem fixed, but I got another problem "Returned values aren't valid, did it run Out of Gas?", do you know why ? – johnho.91 Apr 22 '19 at 12:38
  • Without seeing the source for it, DappToken's transfer() method needs to return a Boolean value. If it doesn't, then the problem would be your require statement before selfdestruct. The ERC20 standard specifies that transfer should return a bool. – Thomas Apr 22 '19 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.