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?
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?
Share Improve this question edited Sep 27, 2022 at 21:19 TylerH 21.1k77 gold badges79 silver badges112 bronze badges asked Nov 21, 2021 at 7:54 GGbroGGbro 411 silver badge4 bronze badges 6-
During formatting your code for easier readability, I found that the cause might be in the definition of
Project
. Can you share its definition as well? (I'm assuming it's eitherstruct
orcontract
). – Petr Hejda Commented Nov 21, 2021 at 9:23 - thank you for your reply, the error refers to the "msg.sender" in the projects new project line '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); emit ProjectStarted( address(newProject), msg.sender, title, description, raiseUntil, amountToRaise );' – GGbro Commented Nov 21, 2021 at 12:01
- hey, i edited the post, thank you for your reply i realy appriciate it, i didnt manage to solve it yet. :) – GGbro Commented Nov 21, 2021 at 12:23
-
This is the reference of the
Project
. I'm looking for the definition - probably starts withstruct Project {
orcontract Project {
. – Petr Hejda Commented Nov 21, 2021 at 12:25 - medium./openberry/… this is the code, hope it helps :)) – GGbro Commented Nov 21, 2021 at 14:50
3 Answers
Reset to default 6The 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
);
If you don't yet know what the value of an address type is, pass it it in as: address(0)
startProject is missing the address variable.