[英]ParserError: Expected ';' but got 'event' -- solidity 0.8 address payable(msg.sender)
I don't know why I still get this error, I have already changed this address payable(msg.sender)
to line 81 (I bold the line below) according to solidity 0.8 update, but it still gives an error.我不知道为什么我仍然得到这个错误,我已经根据 solidity 0.8 更新将这个
address payable(msg.sender)
更改为第 81 行(我将下面的行加粗),但它仍然报错。 Can anyone assist, please?有人可以帮忙吗?
I have indicated line 81 on this code below.我在下面的代码中指出了第 81 行。
CONSOLE ERROR控制台错误
| | 50 |
50 | event ImageCreated( | ^^^^^**
事件 ImageCreated( | ^^^^^**
pragma solidity 0.8.12;
contract GistPin {
string public name = "GistPin";
uint256 public videoCount = 0;
uint256 public imageCount = 0;
mapping(uint256 => Image) public images;
mapping(uint256 => Video) public videos;
struct Image {
uint256 id;
string hash;
string description;
uint256 tipAmount;
address payable author;
}
struct Video {
uint256 id;
string hash;
string title;
address author;
}
event VideoUploaded(
uint256 id,
string hash,
string title,
string description,
address author
);
constructor() public {
name = "GistPin";
}
function uploadVideo(
string memory _videoHash,
string memory _title,
string memory _description
) public {
// Make sure the video hash exists
require(bytes(_videoHash).length > 0);
// Make sure video title exists
require(bytes(_title).length > 0);
// Make sure video description exists
require(bytes(_description).length > 0);
// Make sure uploader address exists
require(msg.sender != address(0));
// Increment video id
videoCount++;
// Add video to the contract
videos[videoCount] = Video(videoCount, _videoHash, _title, msg.sender);
// Trigger an event
emit VideoUploaded(
videoCount,
_videoHash,
_title,
_description,
msg.sender
);
}
event ImageCreated(
uint256 id,
string hash,
string description,
uint256 tipAmount,
address payable author
);
event ImageTipped(
uint256 id,
string hash,
string description,
uint256 tipAmount,
**address payable(msg.sender)** // ERROR LINE 81
);
function uploadImage(string memory _imgHash, string memory _description) public {
// Make sure the image hash exists
require(bytes(_imgHash).length > 0);
// Make sure image description exists
require(bytes(_description).length > 0);
// Make sure uploader address exists
require(msg.sender!=address(0x0));
// Increment image id
imageCount ++;
// Add Image to the contract
images[imageCount] = Image(imageCount, _imgHash, _description, 0, msg.sender);
// Trigger an event
emit ImageCreated(imageCount, _imgHash, _description, 0, msg.sender);
}
function tipImageOwner(uint _id) public payable {
// Make sure the id is valid
require(_id > 0 && _id <= imageCount);
// Fetch the image
Image memory _image = images[_id];
// Fetch the author
address payable _author = _image.author;
// Pay the author by sending them Ether
address(_author).transfer(msg.value);
// Increment the tip amount
_image.tipAmount = _image.tipAmount + msg.value;
// Update the image
images[_id] = _image;
// Trigger an event
emit ImageTipped(_id, _image.hash, _image.description, _image.tipAmount, _author);
}
}
can you add what the exact error your getting from the console你能添加你从控制台得到的确切错误吗
Try this:尝试这个:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;
contract GistPin {
string public name = "GistPin";
uint256 public videoCount = 0;
uint256 public imageCount = 0;
mapping(uint256 => Image) public images;
mapping(uint256 => Video) public videos;
struct Image {
uint256 id;
string hash;
string description;
uint256 tipAmount;
address payable author;
}
struct Video {
uint256 id;
string hash;
string title;
address author;
}
event VideoUploaded(
uint256 id,
string hash,
string title,
string description,
address author
);
constructor() {
name = "GistPin";
}
function uploadVideo(
string memory _videoHash,
string memory _title,
string memory _description
) public {
// Make sure the video hash exists
require(bytes(_videoHash).length > 0);
// Make sure video title exists
require(bytes(_title).length > 0);
// Make sure video description exists
require(bytes(_description).length > 0);
// Make sure uploader address exists
require(msg.sender != address(0));
// Increment video id
videoCount++;
// Add video to the contract
videos[videoCount] = Video(videoCount, _videoHash, _title, msg.sender);
// Trigger an event
emit VideoUploaded(
videoCount,
_videoHash,
_title,
_description,
msg.sender
);
}
event ImageCreated(
uint256 id,
string hash,
string description,
uint256 tipAmount,
address payable author
);
event ImageTipped(
uint256 id,
string hash,
string description,
uint256 tipAmount,
// Declare the variable
address payable myAddress
);
function uploadImage(string memory _imgHash, string memory _description) public {
// Make sure the image hash exists
require(bytes(_imgHash).length > 0);
// Make sure image description exists
require(bytes(_description).length > 0);
// Make sure uploader address exists
require(msg.sender!=address(0x0));
// Increment image id
imageCount ++;
// Add Image to the contract
images[imageCount] = Image(imageCount, _imgHash, _description, 0, payable(msg.sender));
// Trigger an event
emit ImageCreated(imageCount, _imgHash, _description, 0, payable(msg.sender));
}
function tipImageOwner(uint _id) public payable {
// Make sure the id is valid
require(_id > 0 && _id <= imageCount);
// Fetch the image
Image memory _image = images[_id];
// Fetch the author
address payable _author = _image.author;
// Pay the author by sending them Ether
_author.transfer(msg.value);
// Increment the tip amount
_image.tipAmount = _image.tipAmount + msg.value;
// Update the image
images[_id] = _image;
// Trigger an event
emit ImageTipped(_id, _image.hash, _image.description, _image.tipAmount, payable(_author));
}
}
You must declare a variable into ImageTipped event
in this way: address payable myAddress
.您必须以这种方式在
ImageTipped event
中声明一个变量: address payable myAddress
。 And each time you call the event with emit you will have to pass it the msg.sender in this way: payable(msg.sender)
.每次你用 emit 调用事件时,你都必须以这种方式将 msg.sender 传递给它:
payable(msg.sender)
。 For more information see line: 81 and 118 in my code.有关详细信息,请参阅我的代码中的第81和118行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.