Reputation: 41
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
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
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