Type address is not implicitly convertible to expected type contract ERC20

Type address is not implicitly convertible to expected type contract ERC20



I am trying to compile my crowdsale contract and get this error:


" TypeError: Type address is not implicitly convertible to expected
type contract ERC20.
token = 0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf; "
^----------------------------------------^



I suppose putting this address type is wrong, maybe I should remove smth or add smth, can you please help me? I copied my address from ropsten.ether.scan



Thanks in advance!


pragma solidity ^0.4.24;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.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 / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/
contract Crowdsale
using SafeMath for uint256;
using SafeERC20 for ERC20;

// The token being sold
ERC20 public token;

// Address where funds are collected
address public wallet;

// How many token units a buyer gets per wei.
// The rate is the conversion between wei and the smallest and indivisible token unit.
// So, if you are using a rate of 1 with a DetailedERC20 token with 3 decimals called TOK
// 1 wei will give you 1 unit, or 0.001 TOK.
uint256 public rate;

// Amount of wei raised
uint256 public weiRaised;

/**
* 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
);

/**
* @param _rate Number of token units a buyer gets per wei
* @param _wallet Address where collected funds will be forwarded to
* @param _token Address of the token being sold
*/
constructor(uint256 _rate, address _wallet, ERC20 _token) public
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));

rate = 8 * (10**8);
wallet = 0xF76075Cf3B674fB9656E393e9e17091B01243666;
token = 0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf;


// -----------------------------------------
// Crowdsale external interface
// -----------------------------------------

/**
* @dev fallback function ***DO NOT OVERRIDE***
*/
function () external payable
buyTokens(msg.sender);


/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* @param _beneficiary Address performing the token purchase
*/
function buyTokens(address _beneficiary) public payable

uint256 weiAmount = msg.value;
_preValidatePurchase(_beneficiary, weiAmount);

// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);

// update state
weiRaised = weiRaised.add(weiAmount);

_processPurchase(_beneficiary, tokens);
emit TokenPurchase(
msg.sender,
_beneficiary,
weiAmount,
tokens
);

_updatePurchasingState(_beneficiary, weiAmount);

_forwardFunds();
_postValidatePurchase(_beneficiary, weiAmount);


// -----------------------------------------
// Internal interface (extensible)
// -----------------------------------------

/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(_beneficiary, _weiAmount);
* require(weiRaised.add(_weiAmount) <= cap);
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal

require(_beneficiary != address(0));
require(_weiAmount != 0);


/**
* @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met.
* @param _beneficiary Address performing the token purchase
* @param _weiAmount Value in wei involved in the purchase
*/
function _postValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal

// optional override


/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.
* @param _beneficiary Address performing the token purchase
* @param _tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(
address _beneficiary,
uint256 _tokenAmount
)
internal

token.safeTransfer(_beneficiary, _tokenAmount);


/**
* @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.
* @param _beneficiary Address receiving the tokens
* @param _tokenAmount Number of tokens to be purchased
*/
function _processPurchase(
address _beneficiary,
uint256 _tokenAmount
)
internal

_deliverTokens(_beneficiary, _tokenAmount);


/**
* @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.)
* @param _beneficiary Address receiving the tokens
* @param _weiAmount Value in wei involved in the purchase
*/
function _updatePurchasingState(
address _beneficiary,
uint256 _weiAmount
)
internal

// optional override


/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param _weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)

return _weiAmount.mul(rate);


/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal
wallet.transfer(msg.value);






Please provide the code that produced this result.
– shanefontaine
Aug 21 at 3:03





I am using simple crowdsale template from zeppelin (github.com/OpenZeppelin/openzeppelin-solidity/blob/master/…)
– Josephhh
Aug 21 at 3:04





here is the my customized code where I guess the problem is:
– Josephhh
Aug 21 at 3:05





constructor(uint256 _rate, address _wallet, ERC20 _token) public require(_rate > 0); require(_wallet != address(0)); require(_token != address(0)); rate = 8 * (10**8); wallet = 0xF76075Cf3B674fB9656E393e9e17091B01243666; token = 0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf;
– Josephhh
Aug 21 at 3:05





Please edit the post above and include the entire codebase that you have. It is impossible to tell where the error is with just this information.
– shanefontaine
Aug 21 at 3:11




2 Answers
2



Change


token = 0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf;



To


token = ERC20(0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf);



token is of type ERC20, and you are trying to assign it a value of type address. You need to explicitly cast it.


token


ERC20


address



I think we need to explicit cast the address to ERC20 token contract as below


token = ERC20(0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj