我在混音中遇到这个错误:
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/