Search code examples
javascriptblockchainethereumsolidity

ParserError in Solidity 0.8.0


hello Guys !

i'm trying to create a Dapp contracts it works perfectly in 0.4.2 but giving me errors in

latest Sol compiler version.

    pragma solidity >=0.7.0 <0.8.0;
    function endSale() public {
        require(msg.sender == admin);
        require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this)) ));
        admin.transfer( address payable(this).balance)
    }
}

ERROR

enter image description here


Solution

  • Payable should be the recipient, not the sender address. Also, your syntax is slightly incorrect.

    Assuming admin is saved as address (not payable)

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

    And if admin is already address payable, it's enough to call just this

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