1

Get the following error message, which I suspect has something to do with the solidity version 0.5, that I'm using?

Error message

$ truffle test

Using network 'development'.

/contracts/DappTokenSale.sol:39:9: TypeError: Member "transfer" not found or not visible after argument-dependent lookup in address. admin.transfer

Compilation failed. See above.

Truffle v5.0.1 (core: 5.0.1) Node v11.6.0

Code

pragma solidity ^0.5;

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.sender == admin);
    require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));


    admin.transfer(address(this).balance);
}

}

0

1 Answer 1

1

The error is related to the absence of the method “transfer” in the “admin” address.

Simply declare “admin” as “address payable”:

address payable admin;

Starting from compiler version 0.5.0, “address payable” type only has the method cited.

From Solidity documentation:

enter image description here

1
  • You are welcome. Happy to hear that. Please mark as answered the question.
    – Rick Park
    Commented Jan 12, 2019 at 5:37

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