首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我正在获取DeclarationError :未声明的标识符函数setEndTime(uint _endTime)公共onlyOwner

我正在获取DeclarationError :未声明的标识符函数setEndTime(uint _endTime)公共onlyOwner
EN

Ethereum用户
提问于 2021-06-03 23:41:21
回答 1查看 52关注 0票数 0
代码语言:javascript
复制
pragma solidity ^0.5.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/Crowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/distribution/FinalizableCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/emission/AllowanceCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/validation/PausableCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/crowdsale/validation/TimedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/dfbdb11605bab94df6a6b864afc1a068e94a67cc/contracts/token/ERC20/IERC20.sol";

/**
 * @title SampleCrowdsale
 * @dev This is an example of a fully fledged crowdsale.
 * The way to add new features to a base crowdsale is by multiple inheritance.
 * In this example we are providing following extensions:
 * CappedCrowdsale - sets a max boundary for raised funds
 * RefundableCrowdsale - set a min goal to be reached and returns funds if it's not met
 * MintedCrowdsale - assumes the token can be minted by the crowdsale, which does so
 * when receiving purchases.
 *
 * After adding multiple features it's good practice to run integration tests
 * to ensure that subcontracts works together as intended.
 */
contract CresstCrowdsale is CappedCrowdsale,TimedCrowdsale,Pausable,IncreasingPriceCrowdsale,AllowanceCrowdsale,FinalizableCrowdsale {
    uint constant TOKEN_DECIMALS = 18;
    uint8 constant TOKEN_DECIMALS_UINT8 = 18;
    uint constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS;
    
    constructor (
        uint256 openingTime,   // opening time in unix epoch seconds
        uint256 closingTime,        // closing time in unix epoch seconds
        uint256 rate,               // rate, in TKNbits
        address payable wallet,     //the wallet address that will receive the donation
        address payable tokenWallet,  // the crowd sale wallet address
        uint256 initialRate,            //the rate it will start to increase its always greater
        uint256 finalRate,              //the rate it will end when crowd sale stops always  smaller
        uint256 cap,            // total amount for the Crowdsale, in wei
        IERC20 token            // the token contract address
    ) 
    Crowdsale(rate,wallet,token) 
    CappedCrowdsale(cap)
    TimedCrowdsale(openingTime, closingTime)
    IncreasingPriceCrowdsale(initialRate,finalRate)
    AllowanceCrowdsale(tokenWallet)
    FinalizableCrowdsale()
    
    public {
        
        
    }
    
    
    /**
     * @dev Admin can move end time.
     * @param _endTime New end time.
     */
     function setEndTime(uint _endTime) public onlyOwner notFinalized {
        require(_endTime > openingTime);
        closingTime = uint32(_endTime);
    }


     function setStartTime(uint _startTime) public onlyOwner notFinalized {
        require(_startTime < closingTime);
        openingTime = uint32(_startTime);
    }

    function setHardCap(uint _hardCapTokens) public onlyOwner notFinalized {
        require(_hardCapTokens * TOKEN_DECIMAL_MULTIPLIER > cap);
        cap = _hardCapTokens * TOKEN_DECIMAL_MULTIPLIER;
    }
    
     function setNewRate(uint _NewRate) public onlyOwner notFinalized {
        rate = _NewRate;
    }
    
       
}

在这里,我试图添加一些函数,这些函数可以用来修改startdateenddatecaprate,但这给我带来了严重的错误。如果删除这四个函数,代码就可以了,但是我需要这四个函数(setEndTimesetStartTimesetHardCapsetNewRate)。拜托,我该怎么办?

EN

回答 1

Ethereum用户

发布于 2021-06-05 00:54:31

为了使用onlyOwner修饰符,合同应继承Ownable

代码语言:javascript
复制
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/ownership/Ownable.sol";

contract CresstCrowdsale is ..., Ownable {

    function setEndTime(uint _endTime) public onlyOwner notFinalized {
        require(_endTime > openingTime);
        closingTime = uint32(_endTime);
    }
}
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/100284

复制
相关文章

相似问题

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