最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to resolve the error "Invalid type for argument in function call. Invalid implicit conversion from add

programmeradmin2浏览0评论

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 either struct or contract). – 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 with struct Project { or contract 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
 |  Show 1 more ment

3 Answers 3

Reset to default 6

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
);

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论