2

I created crowdsale contract - https://ropsten.etherscan.io/address/0xfbb2759ef0b7169d0a2effa971845ea0f99f87b1

My token - https://ropsten.etherscan.io/token/0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf

I sent myToken to the contract created to fill it up with some tokens.

Then I am sending ETH from different account in order to get myTokens to this account, but there is an error - https://ropsten.etherscan.io/tx/0x9468576385ba10bdac5dc9da7d260c68c8c654a5b06885aa20b38e2799473351

Can you help me to understand why???

Here is the crowdsale contract: Here is my zeppelinSales.sol:

pragma solidity ^0.4.24;
import "zeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "zeppelin-solidity/contracts/math/SafeMath.sol";
import "zeppelin-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 zeppelinSales {
  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 = ERC20(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);
  }
}

Token.sol

    pragma solidity ^0.4.24;
    import "openzeppelin-                        solidity/contracts/token/ERC20/StandardToken.sol";
    contract TestToken is StandardToken {
    string public name = "TMED Token";
    string public symbol = "TMED1";
    uint8 public decimals = 18;
    uint public INITIAL_SUPPLY = 4000000000000000000000000000;
    constructor() public {
      totalSupply_ = INITIAL_SUPPLY;
      balances[msg.sender] = INITIAL_SUPPLY;
    }
    }
  • can you edit post to provide your token smart contract code? – Ha ĐANG Aug 21 '18 at 10:34
  • And your code still have a typo, duplicate of token in token = token = ERC20(0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf); – Ha ĐANG Aug 21 '18 at 10:58
  • @HaĐANG I just added token contract, please check – Josephhh Aug 21 '18 at 15:14
  • ah, you extend from StandardToken then no problem I think – Ha ĐANG Aug 21 '18 at 16:38
  • The gas used by all transaction is the same 21046 and it is just a bit above the minimum transaction fee, my guess is that the error is very early in your fallback function. Can you verify the source code of your contracts in etherscan? – Ismael Aug 22 '18 at 3:44
0

With the rate = 8 * (10**8) a.k.a 800,000,000 token for 1ETH then your crowdsale contract address dont have enough token balance to send, your crowd sale contract address token balance is just 100,000,000

Then you have to fund token to your crowdsale contract first, I think! Or just try to send small ETH to the contract.

Additional: the fallback() function will have very low default gas limit, then when sending ETH to the crowd sale smart contract, try to increase gas limit to maximum value in MEW to ensure enough gas to make tnx successfully.

  • Ha Dang, I tried to send small amout of ETH, same problem check the transaction please - ropsten.etherscan.io/tx/… – Josephhh Aug 21 '18 at 12:50
  • help me guys! please – Josephhh Aug 22 '18 at 2:07
  • Sorry, I have no idea at the moment; did you fix this in your crowdsale smart contract? token = token = ERC20(0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf); – Ha ĐANG Aug 22 '18 at 2:18
  • that was a type in this comment section, but on my sourcode it's fine, I will edit it here – Josephhh Aug 22 '18 at 2:20
  • Please try to send 0.01ETH to crowdsale contract to see what's happen. I'm afraid that 0.00005 ETH is too small then not enough balance to pay the tnx fee – Ha ĐANG Aug 22 '18 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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