Ethereum Crowdsale Discussion

Welcome to the thread about Ethereum Crowdsale. Here you can discuss everything about the code and potential problems that you might stumble upon.


hi filip,

i have 2 problems with the contracts / Crowdsale Setup.

first problem the Crowdsale Contract receive only the amount: 0.00000000000001 Tokenname
but i send to the Crowdsale 10000 , tenthausend Tokens. Like you Show in the Video.

please fix the Missing Parts, somewhere is Math not Correct, or you forgot to Show something on Settings?

and what was with the part about the price, i dont get it… the last video is not the best.
part 1 and 2 is clear, but with number 3 bringing all together, maybe you can make it again, just with more details?

Thank you


It’s hard for me to understand what’s wrong just by reading your question. Could you maybe share your code here? Preferable by sending me a link github or similar.

Hi Filip,

Thank you for your instruction and I am writing you for a question regarding to withdraw the fund after reaching the goao.

I have deployed token.sol and crowdsale.sol as instruction, the codes are copy and pasted so they should be right.

I set 1 ether as goalInEther and set 10mins as durationInMinutes and 1 ether as tokenPrice to test.

I was successfully joined the crowd sale from my metamask with sending twice of 1ther (1000000000000000000 wei) therefore I sent 2 ether in total to crowd sale contract which is more than enough for the goal.

I tried checkGoalReached and safeWithdrawal and expecting to get 2 ether to my myetherwallet address.
However it did not work.

I am not sure what is wrong and there is no video for doing this.
I have attached a screenshot though it seems not showing here.

Please let me know if any advice.



i use your code example from the video.

problem is the 18 decimals,
to receive 10.000 token, i must send 10.000 + 17 Zeros.

so this i figured out by my self.
but still i have the price problem, is it possible to set the price in Wai, and not in Ether.
i saw this on one other video about smart contract.

Did you check the checkGoalReached and safeWithdrawal after the deadline had run out? Because if you do it before the deadline it won’t work. Both functions have the modifier afterDeadline

Glad you solved it. Yes you can set the decimals however you like.

If you want the price in wei just change this line in the crowdsale contract

tokenPrice = tokenPriceInEther * 1 ether;


tokenPrice = tokenPriceInWei * 1 wei;

1 Like

Yes I waited for over 30 mins (I set as 10mins) to do checkGoalReached and safeWithdrawal.

I can see that the uint of crowdsaleDeadline which you can see 1528897899 on the screenshot, it did not change after re-clicking the function. so that it seems not working properly (The time isnt counting)?


I’m not able to replicate it unfortunately. I deployed everything myself and I was able to withdraw everything when the crowdsale was done.

The crowdsaleDeadline should not be updated, that is a constant variable defining the deadline. It’s not a countdown as such. It later on get’s compared to the current timestamp.

Are you sure your beneficiary account haven’t received the 2 ether? Which one is your MyEtherWallet account? Did you do this in the VM or on the testnet?

I did this on Rinkeby Testnet.

I deployed new crowdsales contract with beneficially address to myetherwallet address to see if I get it to my myetherwallet address by doing this, it was metamask address on the video.

It is already after the crowdsaledeadline time and currently the crowdsales address still holding 2 ether (I made HiroCoin) as below. I have done check deadline and safewithdraw. I think it is taking time to process or simply not working in this way?


This is my MEW address

I realized that the 2 ether at previous attempt went back to metamask address as the address was set to beneficially following the video.
Now I am trying again setting the beneficially address to MEW address to see.

Just to inform that none of the things I tried work. I thinkl need to set back beneficials to metamask account as the instruction and the ether went back to metamask account instead of myetherwallet address.

1 Like

Hi guys,
I have a question. Is it safe to use for production -= += in solidity like in the video or should we use SafeMath functions ? Thanks !

Hi @Octales,
I would recommend using SafeMath.sol in production for all math operations. You can check out there you can find the updated versions of SafeMath.sol, Ownable.sol and many more useful and audited contracts.

1 Like

Hi Filip,
First of all, thanks a lot for taking the time to teach us, its been an amazing journey so far :). I appreciate the effort you and Ivan have put into creating this course. No doubt there is a lot to take in but im glad this discussion forum exists for situations as such :).

I have one question actually about this line of code(I will be writing my doubts below within the code itself so you know where and what my doubt is) :

function safeWithdrawal() afterDeadline {
//should we not add a require(msg.sender); here in order to make sure that it is in fact the person firing
this function?

uint amount = balanceOf[msg.sender];
balanceOf[msg.sender] = 0;
if(amount > 0){
balanceOf[msg.sender] = amount;
if(fundingGoalReached && msg.sender == beneficiary){
fundingGoalReached = false;

Thanks :slight_smile:

1 Like

Good question. But it’s actually not necessary. Since we are adjusting the balance by changing balanceOf[msg.sender], there is no way anyone can change the balance of anyone else. You can only modify your own balance. You can’t modify msg.sender to any other address than your own. Let me know if you understand, otherwise I can explain in more detail.

1 Like

I see. No I get it now :). Thanks for that clarification. However, this brings up another question in my head, its more of a wondering, rather as to the subtle differences of “if” and “require” statements. I am talking about this line of code now :

if(fundingGoalReached && msg.sender == beneficiary)
//are we using an if statement here to check two conditions together meaning is it better to use an if statement //here rather than coding it as:
require(msg.sender == beneficiery);
fundingGoalReached = false;

May you please explain if they both impose the same degree of check or if there is any difference at all?

Once again, thank you for taking the time to answer these questions.


My question is about interacting with contracts after their creation.
What are the ways of accessing the functions after closing remix?

So far I’ve been able to do this by compiling the code a second time. Then going to the run tab and pasting the contract address and clicking “At Address” button.

Is there another way of doing this?

Good question. Both would work. If you chose to use require instead of if, it would throw an error if the sender is not the beneficiary. With the if statement it would simply not give any result. But the end result would be the same apart from that.

1 Like