Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested

Viewed 4475

I'm getting this error in remix :

Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested

it refers to msg.sender on line num.9 that i put in bold down below. Thats the code i'm writing:

function startProject(
        string calldata title,
        string calldata description,
        uint durationInDays,
        uint amountToRaise
    ) external {
        uint raiseUntil = block.timestamp.add(durationInDays.mul(1 days));
Project newProject = new Project(
    ***msg.sender***,
    title,
    description,
    raiseUntil,
    amountToRaise
);
projects.push(newProject);

help please :)

2 Answers

The linked code contains a definition of the contract Project and its constructor:

constructor
(
    address payable projectStarter,
    string memory projectTitle,
    string memory projectDesc,
    uint fundRaisingDeadline,
    uint goalAmount
) public {
    // ...
}

It accepts address payable as the first argument. However, msg.sender is not payable by default (since Solidity 0.8.0).

Solution: Typecast the address to address payable:

Project newProject = new Project(
    payable(msg.sender),
    title,
    description,
    raiseUntil,
    amountToRaise
);

If you don't yet know what the value of an address type is, pass it it in as: address(0)

Related