[英]solidity: ParserError: Expected ';' but got '('
//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 ';'在此处输入图像描述一些参考Solidity ParserError: Expected ';' but got '{'
但得到了'{'
Solidity - ParserError: Expected ';' Solidity - ParserError:预期的';' but got '['
但得到'['
First fix your typos function and payable are keywords typos are not tolerated.首先修复您的拼写错误 function 和应付是关键字拼写错误是不能容忍的。 this will fix the expected;
这将解决预期的问题; error
错误
Secondly, a significant problem lies in your 3rd function.其次,一个重大问题在于您的第三个 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. require 语句中的成功是不可见的,因为它尚未使用值初始化。 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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.