简体   繁体   English

坚固性:ParserError:预期';' 但得到'('

[英]solidity: ParserError: Expected ';' but got '('

  1. first of all.I want to check what "solidity: ParserError: Expected ';'首先。我想检查一下“solidity: ParserError: Expected ';' but got '('" want to express.但是得到了'('"想要表达。
  2. How can I improve my code to pass it?如何改进我的代码以通过它?
//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.

相关问题 Solidity ParserError:预期的';' 但得到了“是” - Solidity ParserError: Expected ';' but got 'is' Solidity ParserError:预期的标识符,但得到了 '(' constructor() public { ^ - Solidity ParserError: Expected identifier but got '(' constuctor() public { ^ Solidity 错误:: ParserError: Expected '(' but got 'public' - Solidity Error :: ParserError: Expected '(' but got 'public' "Solidity 错误 :: ParserError: Expected &#39;,&#39; but got &#39;Number&#39;" - Solidity Error :: ParserError: Expected ',' but got 'Number' SOLIDITY:[函数覆盖]:-&gt; ParserError:预期为“{”但得到保留关键字“覆盖” - SOLIDITY : [Function Overridding] : -> ParserError: Expected '{' but got reserved keyword 'override' 无法解决 Solidity 错误 - ParserError: Expected &#39;;&#39; 但得到了“数字”-&gt; first.sol:2:17: | 2 | Pragma 坚固性 0.8.7; | ^^^ - Unable to solve solidity error- ParserError: Expected ';' but got 'Number' --> first.sol:2:17: | 2 | Pragma solidity 0.8.7; | ^^^ 解析器错误:应为“;” 但得到了标识符 - ParserError: Expected ';' but got identifier ParserError:应为“;” 但得到了保留关键字“in” - ParserError: Expected ';' but got reserved keyword 'in' Solidity 0.8.0 中的 ParserError - ParserError in Solidity 0.8.0 得到 parsererror 我在 remix 上写 inheritance solidity 代码我得到了错误 - getting parsererror I write inheritance solidity code on remix i got error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM