当前遵循教程,此错误在我的代码中不断重复。
我试图将msg.sender作为可支付地址添加到结构中,但错误:Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested.会在整个代码中重复。
只是好奇如何将msg.sender设置为结构。
非常感谢。
struct Image {
uint256 id;
string hash;
string description;
uint256 tipAmount;
address payable author; // < ---- Invalid implicit conversion from address to address payable requested.
}
/////
function uploadImage(string memory _imageHash, string memory _description) public {
require(bytes(_imageHash).length > 0, "Must Have Hash!");
require(bytes(_description).length > 0, "Must have description");
require(msg.sender != address(0), "Must have author address");
imageCount++;
images[imageCount] = Image(
imageCount,
_imageHash,
_description,
0,
msg.sender // < ---- Invalid implicit conversion from address to address payable requested.
);
emit ImageCreated(imageCount, _imageHash, _description, 0, msg.sender);
}发布于 2021-05-27 16:16:34
您必须以这种方式转换msg.sender地址:
address payable addr = address(uint160(msg.sender)); 发布于 2021-08-15 05:34:15
msg.sender在payable(msg.sender)中的包装为我提供了坚实的0.8.2
发布于 2021-08-04 00:43:03
请试试这个:
//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.7.0 <0.9.0;
struct Image {
...
address payable author; // < ----
}然后..。
images[imageCount] = Image(
imageCount,
_imageHash,
_description,
0,
payable(msg.sender) // < ----
);https://ethereum.stackexchange.com/questions/99731
复制相似问题