TypeError on Remix for BSC Contract

2.9k views Asked by At

I have this error "TypeError: Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable. --> Driven.sol:233:16: | 233 | return msg.sender; | ^^^^^^^^^^"

for the following function

abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

Please help!

1

There are 1 answers

6
Petr Hejda On BEST ANSWER

Since Solidity 0.8, msg.sender is not payable anymore. You need to cast it to payable first.

function _msgSender() internal view virtual returns (address payable) {
    return payable(msg.sender); // added payable
}

Or you can return just address (not payable):

function _msgSender() internal view virtual returns (address) {  // removed payable
    return msg.sender;
}