【发布时间】:2022-08-19 23:56:55
【问题描述】:
我正在尝试提供应付地址,但在 msg.sender 和 address(_author).transfer(msg.value) 处出现错误。它在函数调用中显示为参数类型无效。请求的从地址到应付地址的隐式转换无效。每次更换相同的错误时,我都尝试了很多方法来解决。在添加应付给作者之前很好,但是当添加应付给作者时,它开始出现错误。在这两个中, msg.sender 和 msg.value
pragma solidity >=0.4.0 <0.9.0;
contract SocialNetwork {
string public name;
uint public postCount = 0;
mapping(uint => Post) public posts;
struct Post {
uint id;
string content;
uint tipAmount;
address payable author;
}
event PostCreated(
uint id,
string content,
uint tipAmount,
address payable author
);
event PostTipped(
uint id,
string content,
uint tipAmount,
address payable author
);
constructor() public {
name = \"Yash university Social Network\";
}
function createPost(string memory _content) public {
//REquire Valid content
require(bytes(_content).length > 0);
// InCREMENT the post count
postCount ++;
// Create the post
posts[postCount] = Post(postCount, _content, 0, msg.sender);
// Trigger event
emit PostCreated(postCount, _content, 0, msg.sender);
}
function tipPost(uint _id) public payable {
//fetch the post
Post memory _post = posts[_id];
//fetch the author
address payable _author = _post.author;
//pay the author
address(_author).transfer(msg.value);
//increment the tip post
_post.tipAmount = _post.tipAmount + msg.value;
//update the post
posts[_id] = _post;
//Trigger an event
emit PostTipped(postCount, _post.content, _post.tipAmount, _author);
}
}
标签: typeerror