O
O
Orion Orion2022-02-20 21:25:54
blockchain
Orion Orion, 2022-02-20 21:25:54

TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address".?

pragma solidity >=0.7.0 <0.9.0;

contract Shop {

    function pay (uint amount) public {
        msg.sender.transfer(amount);
    }

    receive() external payable{}
}


wanted to create a simple smart contract that accepts any incoming funds
and sends the amount to the address that requested it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vicky, 2022-02-20
@Harlock

Starting from version 0.8.x, transferring funds (send and transfer) requires the type to be `address payable`, with `msg.sender` becoming just `address` ( documentation link ). Those. you need to cast it to the `address payable` type and the code should work:
payable(msg.sender).transfer(amount);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question