GGbro
GGbro

Reputation: 41

How to resolve the error "Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested"

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 number 9 below. Here is 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);

Why am I getting this error? How can I resolve it?

Upvotes: 3

Views: 9909

Answers (3)

Petr Hejda
Petr Hejda

Reputation: 43581

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(
    // `msg.sender` is of type `address` - typecasting to `address payable`
    payable(msg.sender),
    title,
    description,
    raiseUntil,
    amountToRaise
);

Upvotes: 6

0x0
0x0

Reputation: 1

startProject is missing the address variable.

Upvotes: 0

Atang Motloli
Atang Motloli

Reputation: 39

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

Upvotes: 0

Related Questions