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

Lesson4编写FundMe.sol遇ParserError报错,求解决方案

解决ParserError: Expected primary expression错误

问题原因

错误源于初始化priceFeed变量的语句末尾缺失了分号。Solidity语法要求每条语句必须以分号结尾,缺失分号会导致解析器无法正确识别后续代码结构,从而抛出语法错误。

修正后的代码

function getPrice() public view returns (uint256) {
    // ABI
    // Address 0x694AA1769357215DE4FAC081bf1f309aDC325306
    AggregatorV3Interface priceFeed = AggregatorV3Interface(0x694AA1769357215DE4FAC081bf1f309aDC325306); // 补充缺失的分号
    (,int price,,,) = priceFeed.latestRoundData();
    // ETH in terms of USD
    // 3000.00000000
    return uint256(price * 1e10); // 1**10 == 10000000000
}

关键说明

  • Solidity中变量声明、赋值等语句必须以分号;结尾,这是语法规则的基本要求。
  • 分号的作用是标记语句的结束,缺失会导致解析器混淆语句边界,引发类似的语法解析错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 11:52:09