1

I do not understand how to fix the error

pragma solidity ^0.4.23;

import "./ERC20.sol";
import "./SafeMath.sol";
import "./MintableToken.sol";


/**
 * @title Crowdsale
 * @dev Crowdsale is a base contract for managing a token crowdsale,
 * allowing investors to purchase tokens with ether. This contract implements
 * such functionality in its most fundamental form and can be extended to provide additional
 * functionality and/or custom behavior.
 * The external interface represents the basic interface for purchasing tokens, and conform
 * the base architecture for crowdsales. They are *not* intended to be modified / overriden.
 * The internal interface conforms the extensible and modifiable surface of crowdsales. Override
 * the methods to add functionality. Consider using 'super' where appropiate to concatenate
 * behavior.
 */
contract Crowdsale {
  using SafeMath for uint256;

 // The token being sold
    MintableToken public token;

    // start and end timestamps where investments are allowed (both inclusive)
    uint256 public ICOStartTime;
    uint256 public ICOEndTime;

    // wallet address where funds will be saved
    address internal wallet;

    // amount of raised money in wei
    uint256 public weiRaised; // internal

    // Public Supply
    uint256 public publicSupply;

    /**
     * event for token purchase logging
     * @param purchaser who paid for the tokens
     * @param beneficiary who got the tokens
     * @param value weis paid for purchase
     * @param amount amount of tokens purchased
     */
    event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);

    // CarHash Crowdsale constructor
    constructor(MintableToken _token, uint256 _publicSupply, uint256 _startTime, uint256 _endTime, address _wallet) public {
        require(_endTime >= _startTime);
        require(_wallet != 0x0);

        // BitNautic token creation
        token = _token;

        // total supply of token for the crowdsale
        publicSupply = _publicSupply;

        // Pre-ICO start Time
        ICOStartTime = _startTime;

        // ICO end Time
        ICOEndTime = _endTime;

        // wallet where funds will be saved
        wallet = _wallet;

    }

    // fallback function can be used to buy tokens
    function() public payable {
        buyTokens(msg.sender);
    }

    // High level token purchase function
    function buyTokens(address beneficiary) public payable {
        require(beneficiary != 0x0);
        require(validPurchase());

        // minimum investment should be 0.05 ETH
        uint256 lowerPurchaseLimit = 0.05 ether;
        require(msg.value >= lowerPurchaseLimit);

        assert(_tokenPurchased(msg.sender, beneficiary, msg.value));

        // update state
        weiRaised = weiRaised.add(msg.value);

        forwardFunds();
    }

    function _tokenPurchased(address /* buyer */, address /* beneficiary */, uint256 /* weiAmount */) internal returns (bool) {
        // TO BE OVERLOADED IN SUBCLASSES
        return true;
    }

    // send ether to the fund collection wallet
    // override to create custom fund forwarding mechanisms
    function forwardFunds() internal {
        wallet.transfer(msg.value);
    }

    // @return true if the transaction can buy tokens
    function validPurchase() internal constant returns (bool) {
        bool withinPeriod = ICOStartTime <= now && now <= ICOEndTime;
        bool nonZeroPurchase = msg.value != 0;

        return withinPeriod && nonZeroPurchase;
    }

    // @return true if crowdsale event has ended
    function hasEnded() public constant returns (bool) {
        return now > ICOEndTime;
    }
bool public checkBurnTokens = false;

    function burnTokens() onlyOwner public returns (bool) {
        require(hasEnded());
        require(!checkBurnTokens);

        token.mint(0x0, publicSupply);
        token.burnTokens(publicSupply);
        publicSupply = 0;
        checkBurnTokens = true;

        return true;
    }

    function getTokenAddress() onlyOwner public view returns (address) {
        return address(token);
}
}

Remix gives the following error:

browser / Crowdsale.sol: 117: 27: 
DeclarationError: Undeclared identifier. 
    function burnTokens () onlyOwner public returns (bool) {
2
  • Help!!! Already a laptop on the wall is ready to smash !!! I do not see what the error is!
    – Sergey
    Commented Jul 2, 2018 at 13:07
  • 1
    Please edit your question to include the error (using the edit link underneath)... that way people do not have to search in the comments in order to get a complete understanding of your problem. Keeping all of the information in one post will help other people to help you. Also, in future, please format your code correctly, using the code formatting button in the editor. In addition, smashing your laptop will not help you solving your problem any quicker. I strongly suggest that you calm down. Commented Jul 2, 2018 at 13:08

3 Answers 3

4

The error message you get probably looks like this:

DeclarationError: Undeclared identifier.
    function burnTokens() onlyOwner public returns (bool) {
                          ^-------^

Did you notice the "arrows" pointing to the issue (^-------^)?

That's because onlyOwner isn't declared in your contract. You probably want to use the Ownable interface, which defines among other things, the onlyOwner modifier.

Change your contract like this:

import "./Ownable.sol";

contract Crowdsale is Ownable {

    . . .

Or define the onlyOwner modifier inside your contract yourself:

  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }
0

There is no function named as burnTokens in MintableToken contract as in line 121.

//token.burnTokens(publicSupply);

I recommend you to include zeppelin contracts and libraries as below:

import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol"; import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol"; import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol";

It compiles in my editor, hope it works for you.

4
  • Thank you!! Now I'll try !! Do I need to add this function to MintableToken?
    – Sergey
    Commented Jul 2, 2018 at 13:28
  • Now, the error is: browser / Crowdsale.sol: 122: 9: TypeError: Member "burnTokens" not found or visible after MindableToken token.burnTokens (publicSupply); ^ -------------- ^
    – Sergey
    Commented Jul 2, 2018 at 13:33
  • 1
    @Sergey - that is a different question from your original question. As StackExchange is a Q&A site and not a forum, you should only ask for a solution to one issue at a time, and not ask multiple questions in the same post. Otherwise the search mechanism will not work very well. Please post another question (you can refer back to this question if you need to do so). Commented Jul 2, 2018 at 18:02
  • @sergey please read my answer carefully.i stated that there is no function named as burnTokens in mintable token contract. Therefore, I just commented it out. I will try to help you but please try to understand what is suggested. Commented Jul 2, 2018 at 22:11
0

Here is another solution to the question, though not directly relevant for the OP's case. Potentially useful for others confounded by similar compilation failures.

DeclarationError: Undeclared identifier.
  --> contracts/blankNFT.sol:24:9:
   |
24 |         _**setTokenURI**(newItemId, tokenURI);
   |         ^^^^^^^^^^^^


Error HH600: Compilation failed

Breaking change when using pragma 0.8 if trying to call _setTokenURI, which is no longer included.

Solution --> either omit the function (if unnecessary) or try this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.