3

I've used the default crowdfunding code from the ethereum website, but I'm having a lot of trouble figuring out how to set the price for each token as an ether decimal (e.g. 0.0005 ether for each token)

Another problem I have is after creating the contract, I try to send ether from MyEtherWallet and this error comes up.

Error

1

I am working via the same route, I suggest using https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/crowdsale/Crowdsale.sol. A lot of people have just used this and adapted it. You need to deploy via myetherwallet from what I have seen. Make sure you test it well before making it available. Also use etherscan.io and enter addresses of current presales and for many there are contracts accessible via etherscan.io.

0

I would suggest you to calculate this in Wei, that will solve your problem. Go to https://etherconverter.online/, enter 1 in the "Ether" field and set the price to that in wei. I have made a little example, use only if tested well and if you solved security issues!

contract Crowdsale {
    uint tokenPrice = 500000000000000 wei;
    uint public tokensToGet = 0;
    function buyToken() payable returns (uint){
        tokensToGet = msg.value / tokenPrice;
        return tokensToGet;
    }
}

Instead of "wei" you could also use "szabo" etc. like seen on the page. Please make sure to only use lowercase ("WEI", "Wei", "weI" would not work). If you now would send 1 Ether, it would convert it with the price per token (0.0005) and tokensToGet would be 2000 (= 2.000 tokens). I habe made "tokensToGet" public because I use Remix and can then directly output this variable. Test it on Remix and use the Javascript VM :). Hope I helped!

0

In my experience, the error you posted is often displayed when your token price / rate variables are set incorrectly, and you attempt to make a purchase which will cause the specified payable function to throw (buyToken() in your case).

Are you hard-coding the token price / rate within the contract, or are you passing in values through the Crowdsale constructor (through Truffle or Remix)? If you are doing the latter (and you should be) remember to pass in your wei values as strings ("1000000000000000000" not 1000000000000000000)

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.