You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Solidity合约部署报ParserError: Expected '{' but got '('问题求助

问题原因
  • 核心解析错误:stake函数定义中多了一对多余的圆括号。Solidity函数的标准定义结构为function 函数名(入参列表) 可见性 修饰符 returns(返回值列表) { 函数体 },你在payable修饰符后额外添加了(),编译器期望读取函数体起始符{时读到了(,因此触发对应报错。
  • 额外笔误:常量treshold拼写错误,正确拼写为threshold,该问题不会触发解析错误,属于语义笔误建议同步修正。
修正后完整代码
pragma solidity >=0.6.0 <0.7.0;

import "hardhat/console.sol";
import "./ExampleExternalContract.sol";

contract Staker {
    
    ExampleExternalContract public exampleExternalContract;
    mapping(address => uint256) public balances;
    uint256 public constant threshold = 1 ether;
    event Stake(address staker, uint256 amount);
    
    constructor(address exampleExternalContractAddress) public {
        exampleExternalContract = ExampleExternalContract(exampleExternalContractAddress);
    }
    
    function stake() public payable {
        balances[msg.sender] = msg.value;
        emit Stake(msg.sender, msg.value);
    }
}

内容的提问来源于stack exchange,提问作者user16028670

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 15:48:02