Crowdsale: DeclarationError: Identifier not found or not unique. ERC20 _token, ^---^

How to resolve this issue?

Here is my CROWDSALE contract:

    pragma solidity ^0.5.0;
    
    
    import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/Crowdsale.sol";
    import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/validation/CappedCrowdsale.sol";
    import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/validation/TimedCrowdsale.sol";
    
    
    contract ExampleTokenCrowdsale is CappedCrowdsale, TimedCrowdsale{
    
    	//minimum investor Contribution - 0.1 ether
    	//minimum investor Contribution - 1 ether
    	uint256 public investorMinCap = 100000000000000000;
    	uint256 public investorHardCap = 1000000000000000000;
    
    	mapping(address => uint256) public contributions;
    
    	constructor(uint256 _rate,
    	  address _wallet,
    	  ERC20 _token,
    	  uint256 _cap,
    	  uint256 _openingTime,
    	  uint256 _closingTime)
    	Crowdsale(_rate, _wallet, _token)
    	CappedCrowdsale(_cap)	
    	TimedCrowdsale(_openingTime, _closingTime)
    	public{
    	}
    
    
      function _preValidatePurchase(
        address _beneficiary,
        uint256 _weiAmount
      )
        internal
      {
        super._preValidatePurchase(_beneficiary, _weiAmount);
        uint256 _existingContribution = contributions[_beneficiary];
        uint256 _newContribution = _existingContribution.add(_weiAmount);
        require(_newContribution >= investorMinCap && _newContribution <= investorHardCap);
    	contributions[_beneficiary] = _newContribution;     
      }
    }

and i see error, why?

1 Like

You need to import the ERC20 library from OZ.

Do You mean:

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/token/ERC20/ERC20.sol";

?
If Yes now I have 4 more errors

This is often the case. The compiler will stop on error. When you fix this one it will compile further and catch any errors to. You must Debug them and figure out what is going on. Eventually you will compile successfully. The error message is a good indication of what the compiler does not like. The more you debug the more you learn and the better you will get.

1 Like

I really want to learn and learn everyday but in this week Iā€™m really busy :frowning: Do You know and can You share with simple crowdsale contract with function: capped and timed? Thank You Sir!

Well I was just providing a bit of help. I code at an hourly rate!

1 Like

Ok I understand.
So please PM me for that simple contract. What is the price :slight_smile: Thanks Friend

change ERC20 with IERC20

You are using old version of OZ contracts
Check for the ones for solidity 0.5

Have a look at Simple ERC20 Crowdsale