Compilation error, Code is not working in 8.7 version

pragma solidity 0.8.7;

contract contractPayable{

mapping(address => uint) balance;
    
    event depositDone(uint amount, address indexed depositedTo);
    
    function deposit() public payable returns (uint)  {
        balance[msg.sender] += msg.value;
        emit depositDone(msg.value, msg.sender);
        return balance[msg.sender];
    }
    
    function withdraw(uint amount) public returns (uint){
        require(balance[msg.sender] >= amount);
        balance[msg.sender] -= amount;
      address payable toSend = 0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB; // compilation error 
        payable(toSend).transfer(amount); 
    }
    
    function getBalance() public view returns (uint){
        return balance[msg.sender];
    }
    
    function transfer(address recipient, uint amount) public {
        require(balance[msg.sender] >= amount, "Balance not sufficient");
        require(msg.sender != recipient, "Don't transfer money to yourself");
        
        uint previousSenderBalance = balance[msg.sender];
        
        _transfer(msg.sender, recipient, amount);
                
        assert(balance[msg.sender] == previousSenderBalance - amount);
    }
    
    function _transfer(address from, address to, uint amount) private {
        balance[from] -= amount;
        balance[to] += amount;
    }


}
1 Like

What is the error your facing? Could you share an screenshot of it ?

Carlos Z

Hi @Gaurav_Sahoo,

I’ve explained what the problem is and how to resolve it in the other discussion topic you’ve posted with the same issue and the same code. Here’s a link to my answer …

https://studygroup.moralis.io/t/compilation-error-in-8-7-version/45238/3?u=jon_m

Once you are happy that you’ve understood the issue, perhaps you could delete this topic, so that we only have one version.