gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 01:26:46 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com