javascript - 如何解决错误 "Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested"

标签 javascript blockchain solidity web3js remix

我在混音中遇到这个错误:

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

它指的是下面第 9 行的 msg.sender。这是我正在编写的代码:

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

为什么会出现此错误?我该如何解决?

最佳答案

linked code包含 contract Project 及其 constructor 的定义:

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

它接受 address payable 作为第一个参数。但是,默认情况下,msg.sender 不是payable(自 Solidity 0.8.0 起)。

解决方案:address 类型转换为 address payable:

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

关于javascript - 如何解决错误 "Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70052775/

相关文章:

javascript - Mocha 中的回调在哪里以及如何定义?

javascript - 谷歌应用程序脚本 : how to persist data in spreadsheet between different function calls?

apache - hyperledger sawtooth是apache还是intel公司旗下的?

blockchain - 我无法使用 ipfs

blockchain - 函数中返回参数的数据位置必须是 "memory",但没有给出

javascript - 从JSON字符串获取数据,foreach,多个同类型

javascript - 使用 MySQL 自动完成

blockchain - 智能合约如何处理多个用户和不同的存储?

python - 尝试从 chainlink 导入时 brownie-config 重新映射错误

node.js - Openzeppelin 中已为 Context.sol 声明了标识符