0

Is someone please able to clarify if I wanted 1000 tokens to be issued for 1 ether then what would I enter the price value in the contract.

function Crowdsale(
    address ifSuccessfulSendTo,
    uint fundingGoalInEthers,
    uint durationInMinutes,
    uint etherCostOfEachToken,
    address addressOfTokenUsedAsReward
) public {
    beneficiary = ifSuccessfulSendTo;
    fundingGoal = fundingGoalInEthers * 1 ether;
    deadline = now + durationInMinutes * 1 minutes;
    price = etherCostOfEachToken * 1 ether;
    tokenReward = token(addressOfTokenUsedAsReward);
}

I tried the below 3 options

0.001 but the contract won't accept anything i.e 0.xxxx

1000 and then the contract always never has enough GAS and I tried 0.0001 and it won't execute

I changed the code to be

price = etherCostOfEachToken * 0.001 ether;

and the contract runs but I get 0.0000001 of that token instead upon sending ether.

So can anyone please tell me from their experience what was the right value to put in to get 1000 tokens for 1 ether?

Thanks

0

The example contract at https://www.ethereum.org/crowdsale assumes the price for a token is an integer amount of ethers.

To set the price in miliethers you need to modify the constructor function

function Crowdsale(
    address ifSuccessfulSendTo,
    uint fundingGoalInEthers,
    uint durationInMinutes,
    uint miliEtherCostOfEachToken,
    address addressOfTokenUsedAsReward
) {
    beneficiary = ifSuccessfulSendTo;
    fundingGoal = fundingGoalInEthers * 1 ether;
    deadline = now + durationInMinutes * 1 minutes;

    // Price in miliethers
    price = miliEtherCostOfEachToken * 0.001 ether;

    tokenReward = token(addressOfTokenUsedAsReward);
}

If you set miliEtherCostOfEachToken to 1, and send 1 ether to the contract you should get 1000 tokens.


From the crowdsale page it requires the token to be configured with decimals set to 0.

You will have to modify the crowdsale fallback function to account for other values.

For example if the token is 18 decimals you should modify like this

function () payable {
    require(!crowdsaleClosed);
    uint amount = msg.value;
    balanceOf[msg.sender] += amount;
    amountRaised += amount;

    // We assume the token has 18 decimals
    tokenReward.transfer(msg.sender, amount * 10**18 / price);

    FundTransfer(msg.sender, amount, true);
}
  • Thanks for your help mate, however it seems to be behaving similarly to setting price=ethercostofeachtoken * 0.001 as i have tried above earlier. upon sending 0.1 ether to the contract instead of recieving 100 of the token the contract instead sends back 0.0000000000000001 of the token. ropsten.etherscan.io/tx/… – Tanveer Roowala Mar 18 '18 at 22:20
  • From the crowdsale page ethereum.org/crowdsale, it requires the token to be configured with decimals set to 0. You will have to modify the crowdsale fallback function to account for other values. – Ismael Mar 18 '18 at 23:19
  • Thanks heaps that was it , tokenReward.transfer(msg.sender, amount * 10**18 / price); Problem solved :) – Tanveer Roowala Mar 19 '18 at 2:49

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.