首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >中的可靠预期不明错误- Remix

中的可靠预期不明错误- Remix
EN

Stack Overflow用户
提问于 2021-04-09 08:26:22
回答 1查看 193关注 0票数 1

编译器报告了下面所附的错误;非常奇怪,因为我跟随课程的导师,他建议我使用较旧版本的remix,我在类似的问题中读到,“返回”应该是单数,但他的代码编译没有问题,无论如何,我尝试了,但没有起作用;他使用的是^0.4.11,我正在使用^0.8.4,尽管当我降级到以前的版本时,这个问题仍然存在。

错误:

代码语言:javascript
复制
ParseError: Expected '{' but
got 'constant' -->
tests/pendulum_ico.sol:28:60: |
28 | function 
equity_in_pendulum(address 
investor) external constant 
returns (uint) { | ^^^^^^^^

代码:

代码语言:javascript
复制
pragma solidity ^0.8.3;

contract pendulum_ico {
    
// Introducing the maximum number of Pendulum available for sale

    uint public max_pendulum = 1000000;
    
// Introducing the USD to Pendulum conversion relocatable

    uint public usd_to_pendulum = 1000;
    
// Introducing the total number of Pendulum that have been bought by the investors

    uint public total_pendulum_bought = 0;
    
// Mapping from the investor address to its equity in Pendulum and usd_to_pendulum

    mapping(address => uint) equity_pendulum;
    mapping(address => uint) equity_usd;
    
// Checking if an investor can buy Pendulum

    modifier can_buy_pendulum(uint usd_invested) {
        require (usd_invested * usd_to_pendulum + total_pendulum_bought <= max_pendulum);
        _;
    }
    
// Getting the equity in Pendulum of an investor

    function equity_in_pendulum(address investor) external constant returns (uint) { 
        return equity_pendulum[investor];
    }                             
    
// Getting the equity in USD of an investor

    function equity_in_usd(address investor) external constant returns (uint) {
        return equity_usd[investor];
    }
    
// Buying Pendulum 

    function buy_pendulum(address investor, uint usd_invested) external
    can_buy_pendulum(usd_invested) {
        uint pendulum_bought = usd_invested * usd_to_pendulum;
        equity_pendulum[investor] += pendulum_bought;
        equity_usd[investor] = equity_pendulum[investor] / 1000;
        total_pendulum_bought += hadcoins_bought;
        
    }
    
// Selling Pendulum 

    function sell_pendulum(address investor, uint pendulum_sold) external {
        equity_pendulum[investor] -= pendulum_sold;
        equity_usd[investor] = equity_pendulum[investor] / 1000;
        total_pendulum_bought -= pendulum_sold;
    }
    
}
EN

回答 1

Stack Overflow用户

发布于 2021-04-09 09:01:43

从0.4 a到0.5之间的打破更改列表

现在不允许使用constant作为函数状态可变修饰符。

在0.8中,您还可以将函数声明为视图函数,这符合0.4 constant中定义的状态不可变性标准。

代码语言:javascript
复制
function equity_in_pendulum(address investor) external view returns (uint) { 
    return equity_pendulum[investor];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67017605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档