Hi Filip,
Code has a compilation which is available on the below link, It says “transfer/send function is only available for address type payable not address”.
https://github.com/filipmartinsson/solidity-0.7.5/blob/main/transfer-assignment-solution.sol
Note:- In your video, You are using the transfer function to send eth but you did not mention to whom you are sending. In the transfer function, you just pass the amount as an argument but you missed the recipient address.
https://academy.ivanontech.com/lessons/transfer
pragma solidity 0.8.7;
contract Bank {
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;
msg.sender.transfer(amount); // Compilation error in this line. " transfer is only available for adress type payable not adress"
return balance[msg.sender];
}
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;
}
}