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. Can anyone assist, please?
I have indicated line 81 on this code below.
CONSOLE ERROR
| 50 | event 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
. And each time you call the event with emit you will have to pass it the msg.sender in this way: payable(msg.sender)
. For more information see line: 81 and 118 in my code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.