//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0<0.9.0;
contract Withdraw{
constructor()payable{}
fucntion withdrawByTransfer() public {
paybale(msg.sender).transfer(1 ether);
}
fucntion withdrawBySend()public{
bool success = paybale(msg.sender).send(1 eth);
require(succeess);
}
fucntion withdrawByCall() public returns(bytes memory){
(bool succeess,bytes memory result) = payable(msg.sender).call{value: require(success)};
return result;
}
}
enter image description here some ref Solidity ParserError: Expected ';' but got '{'
First fix your typos function and payable are keywords typos are not tolerated. this will fix the expected; error
Secondly, a significant problem lies in your 3rd function. A basic rule in programming is the right side of the expression gets executed first, so in this line
(bool success,bytes memory result) = payable(msg.sender).call{value: require(success)};
success in the require statement is not visible since it has not been initialized with a value yet. but even if success does have a value the argument 'value' does not accept a require statement as a value here is how you fix it.
function withdrawByCall() public payable returns(bytes memory){
(bool success,bytes memory result) = payable(msg.sender).call{value: msg.value}(" ");
require(success);
return result;
}
Here is the completed code
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0<0.9.0;
contract Withdraw {
constructor() payable {}
function withdrawByTransfer(uint256 amount) public payable {
payable(msg.sender).transfer(amount);
}
function withdrawBySend(uint256 amount) public payable {
bool success = payable(msg.sender).send(amount);
require(success, "Failed to send Ether");
}
function withdrawByCall(uint256 amount) public returns(bytes memory) {
(bool success, bytes memory result) = payable(msg.sender).call{value: amount}("");
require(success, "Failed to withdraw Ether");
return result;
}
}
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.