---
title: "Discussion on \"The 2018 guide to writing (and testing) real world crowdsale contracts\" | Hashnode"
description: "Discussion on \"The 2018 guide to writing (and testing) real world crowdsale contracts\". It's no secret - ICOs are all the rage these days. Many new companies are raising millions of dollars by selling their tokens in crowdsale. If you are reading this article, you are probably pursuing the idea of doing an ICO.\nI wrote an article a few ..."
url: "https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [The 2018 guide to writing (and testing) real world crowdsale contracts](https://hashnode.com/post/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts?utm_source=hashnode&utm_medium=feed)

It's no secret - ICOs are all the rage these days. Many new companies are raising millions of dollars by selling their tokens in crowdsale. If you are reading this article, you are probably pursuing the idea of doing an ICO. I wrote an article a few ...

Jan 23, 2018 · hashnode.com  
Updated Feb 1, 2018  
Read the article

-   [#ethereum](https://hashnode.com/tag/ethereum)
-   [#blockchain](https://hashnode.com/tag/blockchain)
-   [#smart-contracts](https://hashnode.com/tag/smart-contracts)
-   [#solidity](https://hashnode.com/tag/solidity)

## Written by

[Sandeep Panda](https://hashnode.com/@sandeep)

@sandeep · Bangalore

  
[View profile](https://hashnode.com/@sandeep)

co-founder, Hashnode

I am the Co-Founder of Hashnode. I write (about) code and keep interest in Venture Funding and startups. Feel free to contact me at sandeep@hashnode.com.

## Responses 27

Markdown supported · ⌘↵ to post

[victor perez](https://hashnode.com/@vicrew12)

[Jun 9, 2019](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5cfd3c9daaa03f835851f0e3)

hola como construimos la frond end para la ICO

[Solomon Ezeabasili](https://hashnode.com/@solocrypto)

[Apr 11, 2019](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5caf5152129ffce234faf272)

I tried this on ropsten testnet. Everything worked fine.... Then i deployed on mainnet , the tokens generated were invalid. the smart contract is invalid, lost etherum used in creating on mainnet.

[Olga Miller](https://hashnode.com/@jonnyoly)

[Dec 12, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5c117d895858a0172a96120e)

Try to deploy your crowdsale smart contract on the Ethereum blockchain through mywish.io

[Igor Yalovoy](https://hashnode.com/@ylv)

[Aug 2, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5b63332bc4c0397e69370681)

```
if ((stage == CrowdsaleStage.PreICO) && (token.totalSupply() + tokensThatWillBeMintedAfterPurchase > totalTokensForSaleDuringPreICO)) {
        msg.sender.transfer(msg.value); // Refund them
        EthRefunded("PreICO Limit Hit");
        return;
      }
```

It is better to user `revert` here?

[Angga Andrean](https://hashnode.com/@alphamale)

[Jul 7, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5b40badaacff13923ecc9f8d)

would you share your version truffle, zeppelin ?? or anybody here can help me ?

```
$ truffle compile
Compiling .\contracts\ElectroLightCrowdsale.sol...
Compiling .\contracts\ElectroLightToken.sol...
Compiling .\contracts\Migrations.sol...
Compiling zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol...
Compiling zeppelin-solidity/contracts/crowdsale/RefundableCrowdsale.sol...
Compiling zeppelin-solidity/contracts/token/MintableToken.sol...
Compiling zeppelin-solidity\contracts\crowdsale\Crowdsale.sol...
Compiling zeppelin-solidity\contracts\crowdsale\FinalizableCrowdsale.sol...
Compiling zeppelin-solidity\contracts\crowdsale\RefundVault.sol...
Compiling zeppelin-solidity\contracts\math\SafeMath.sol...
Compiling zeppelin-solidity\contracts\ownership\Ownable.sol...
Compiling zeppelin-solidity\contracts\token\BasicToken.sol...
Compiling zeppelin-solidity\contracts\token\ERC20.sol...
Compiling zeppelin-solidity\contracts\token\ERC20Basic.sol...
Compiling zeppelin-solidity\contracts\token\MintableToken.sol...
Compiling zeppelin-solidity\contracts\token\StandardToken.sol...

zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol:22:37: ParserError: Expected token LBrace got 'View'
  function validPurchase() internal view returns (bool) {
                                    ^
,zeppelin-solidity/contracts/crowdsale/Crowdsale.sol:94:37: ParserError: Expected token LBrace got 'View'
  function validPurchase() internal view returns (bool) {
                                    ^
,zeppelin-solidity/contracts/crowdsale/RefundableCrowdsale.sol:56:33: ParserError: Expected token LBrace got 'View'
  function goalReached() public view returns (bool) {
                                ^
,zeppelin-solidity/contracts/math/SafeMath.sol:9:47: ParserError: Expected token LBrace got reserved keyword 'Pure'
  function mul(uint256 a, uint256 b) internal pure returns (uint256) {
                                              ^
,zeppelin-solidity/contracts/token/BasicToken.sol:38:45: ParserError: Expected token LBrace got 'View'
  function balanceOf(address _owner) public view returns (uint256 balance) {
                                            ^
,zeppelin-solidity/contracts/token/ERC20.sol:12:61: ParserError: Expected token LBrace got 'View'
  function allowance(address owner, address spender) public view returns (uint256);
                                                            ^
,zeppelin-solidity/contracts/token/ERC20Basic.sol:11:42: ParserError: Expected token LBrace got 'View'
  function balanceOf(address who) public view returns (uint256);
                                         ^
,zeppelin-solidity/contracts/token/StandardToken.sol:60:63: ParserError: Expected token LBrace got 'View'
  function allowance(address _owner, address _spender) public view returns (uint256) {
                                                              ^
Compiliation failed. See above.
```

[ChiragMaliwal](https://hashnode.com/@cmaliwal)

[May 7, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5af0a2cd5333a4e941f8d744)

Hello thanks for the good article.

```
uint256 unsoldTokens = totalTokensForSale - alreadyMinted;
      if (unsoldTokens > 0) {
        tokensForEcosystem = tokensForEcosystem + unsoldTokens;
      }
```

Just because of these 3 lines I am getting error : `could potentially lead to re-entrancy vulnerability. <br/><i>Note:</i> Modifiers are currently not considered by this static analysis.`

[Nilanjan Maity](https://hashnode.com/@maityneil001)

[Apr 27, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5ae2cbbadf82667b35735975)

Hello [Sandeep Panda](https://hashnode.com/@sandeep), first of all, thanks for writing this awesome article. This really helps. I followed everything and it worked all fine until when I added the token in meta mask it is showing me 0 nT (nT is the symbol I updated).

What might I be doing wrong?

[KC Tam](https://hashnode.com/@kctam)

[Apr 23, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5add8a62d4e5fdf3157487c7)

Hi Sandeep, Great work! Based on your work I have used geth to inspect what happens inside the ethereum network when executing the testing items. Here I documented the whole process and hope to serve as a companion guide to your great work. You can find it [here](https://medium.com/@kctheservant/a-companion-guide-to-real-world-crowdsale-contracts-6534d3577b3e) . cheers, kc

[Daniel Tung](https://hashnode.com/@tytung)

[Apr 5, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5ac59a655dd21e2b30c8db7e)

I would like to add the following token distribution mechanism: to let each user get extra tokens proportional to the total number of tokens sold, i.e. the more tokens are sold in total, the more extra tokens each user will receive. How to do this in the codes? Thanks.

[John Christian](https://hashnode.com/@jc111)

[Mar 28, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5abbb2dd0796a89856bee2e9)

Sandeep - any chance you'd be willing to write a similar article or ebook on how to do these exact things using Stellar Smart Contracts?

[Sandeep Panda](https://hashnode.com/@sandeep)

[Mar 28, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5abbb2dd0796a89856bee2e9#reply-5abbb3380796a89856bee306)

Hi.. Check out [tokenlauncher.co.](https://tokenlauncher.co./) I built this to show how the same setup can be achieved using Stellar.

[ChiragMaliwal](https://hashnode.com/@cmaliwal)

[Mar 13, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa7a85d9026e896356a8c11)

How can we get the abi of this contract ?

[Shubham Constacloud](https://hashnode.com/@ShubhamCloud)

[Mar 16, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa7a85d9026e896356a8c11#reply-5aab943fc5ecf9b80f1ff9e4)

You can get your contract abi after verify from etherscan by passing your contract address,contract name,compilter version,your contracts complete source code and bytcode but i already tried and got some error. i got my abi from contract json file into build directory.

[Tran Tho](https://hashnode.com/@trantho)

[Mar 12, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa6988b3f00581e280524ee)

Hi gys After I Deploy to Ropsten TestNet Success, then I go to MetaMask -> Tokens -> Add Token. Paste the token address, but 0 in my Token :( This TX [ropsten.etherscan.io/tx/0xa85ba8a43a7cb7a95fe0fde…](https://ropsten.etherscan.io/tx/0xa85ba8a43a7cb7a95fe0fde7ad00cb77221f1df39b8a9bfa265bd6b0d8e54e7a)

[Tran Tho](https://hashnode.com/@trantho)

[Mar 12, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa6988b3f00581e280524ee#reply-5aa699203f00581e2805250b)

My balance new Token 0, any body can help me?

[Tony](https://hashnode.com/@Tonytl)

[Mar 13, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa6988b3f00581e280524ee#reply-5aa769be9026e896356a8811)

0x8F03b85206128395D156Eadbd9cE8eDBd0cc537D this should be your token address

[Tran Tho](https://hashnode.com/@trantho)

[Mar 13, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa6988b3f00581e280524ee#reply-5aa7f1939026e896356a8ea0)

New Transaction deployed but my owner banlance = 0 and nobody can send ETH to this transaction :( [ropsten.etherscan.io/address/0x6a71265726ceb2c4b0…](https://ropsten.etherscan.io/address/0x6a71265726ceb2c4b0a2ffcedc93a310b0f7dfaf)

[ChiragMaliwal](https://hashnode.com/@cmaliwal)

[Mar 8, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa141dde96b069606054b6e)

Please have a look on this issue : [ethereum.stackexchange.com/questions/42122/declar…](https://ethereum.stackexchange.com/questions/42122/declarationerror-identifier-not-found-or-not-unique/)

Getting error : browser/mycontract.sol:64:27: DeclarationError: Identifier not found or not unique. contract StandardToken is ERC20, BasicToken { ^---^

browser/mycontract.sol:64:34: DeclarationError: Identifier not found or not unique. contract StandardToken is ERC20, BasicToken { ^---^

[ChiragMaliwal](https://hashnode.com/@cmaliwal)

[Mar 8, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa141b0e96b069606054b4f)

Is necessary to use metamask with infura ?

[Mykolas Malaiška](https://hashnode.com/@Maiklas)

[Mar 7, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa057a80430f87244d40ca8)

Hello,

An error occurred while testing

Contract: HashnodeCrowdsale ✓ should deploy the token and store the address (97ms) ✓ should set stage to PreICO (109ms) 1) one ETH should buy 5 Hashnode Tokens in PreICO

```
Events emitted during test:
---------------------------

Mint(to: <indexed>, amount: 5000000000000000000)
Transfer(from: <indexed>, to: <indexed>, value: 5000000000000000000)
TokenPurchase(purchaser: <indexed>, beneficiary: <indexed>, value: 1000000000000000000, amount: 5000000000000000000)
EthTransferred(text: forwarding funds to wallet)

---------------------------
✓ should transfer the ETH to wallet immediately in Pre ICO (572ms)
✓ should set variable `totalWeiRaisedDuringPreICO` correctly (41ms)
✓ should set stage to ICO (103ms)
2) one ETH should buy 2 Hashnode Tokens in ICO

Events emitted during test:
---------------------------

Mint(to: <indexed>, amount: 3000000000000000000)
Transfer(from: <indexed>, to: <indexed>, value: 3000000000000000000)
TokenPurchase(purchaser: <indexed>, beneficiary: <indexed>, value: 1500000000000000000, amount: 3000000000000000000)
EthTransferred(text: forwarding funds to refundable vault)

---------------------------
✓ should transfer the raised ETH to RefundVault during ICO (265ms)
✓ Vault balance should be added to our wallet once ICO is over (767ms)
```

7 passing (3s) 2 failing

1) Contract: HashnodeCrowdsale one ETH should buy 5 Hashnode Tokens in PreICO: Uncaught ReferenceError: HashnodeToken is not defined at test/TestCrowdsale.js:26:32 at <anonymous> at process.\_tickCallback (internal/process/next\_tick.js:188:7)

2) Contract: HashnodeCrowdsale one ETH should buy 2 Hashnode Tokens in ICO: Uncaught ReferenceError: HashnodeToken is not defined at test/TestCrowdsale.js:69:32 at <anonymous> at process.\_tickCallback (internal/process/next\_tick.js:188:7)

[Soubhik Ghorai](https://hashnode.com/@soubhik)

[Apr 3, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5aa057a80430f87244d40ca8#reply-5ac326ab28aa3b76134f4fcb)

Any luck with this? I have the same issue and can't figure out what's wrong.

[Martin Blanco](https://hashnode.com/@kaptincho)

[Mar 6, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be)

I would like the tokens to be distributed at the end of the ico, how can we do this?

[Sandeep Panda](https://hashnode.com/@sandeep)

[Mar 7, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be#reply-5a9fbbe60430f87244d408ce)

Instead of transferring the tokens to the users immediately, you can maintain a mapping which stores the pending token balance of each user. Once the ICO is over, you can make the actual transfer via a function call.

[Vamsee](https://hashnode.com/@vamsee)

[Mar 25, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be#reply-5ab7f80a17ffdb93140852ed)

Hi, trying to add a transfer test like this but it is failing.

it('Token transfer', async () => { const contractInstance = await HashnodeCrowdsale.deployed() let ecoSystemBalance = await web3.eth.getBalance(accounts\[9\])

```
const tokenAddress = await contractInstance.token.call()
const hashToken = HashnodeToken.at(tokenAddress)

const owner = await hashToken.owner.call()
console.log(owner)
await hashToken.approve(accounts[4], 4)
console.log(await hashToken.allowance(owner, accounts[4]))
await hashToken.transferFrom(owner, accounts[4], 3)

let receiverBalance = await web3.eth.getBalance(accounts[4])
receiverBalance = receiverBalance.toNumber()

assert.equal(receiverBalance, 3, 'Transfer failed')
```

})

getting this error. Any idea how to get that working? Tried with other from addresses like accounts\[9\] but getting the same error.

\== output of the test run ===

0x85d22c38d2b791a5803fc3f15267fda1b0473c3b BigNumber { s: 1, e: 0, c: \[ 0 \] }

```
Events emitted during test:
---------------------------

Approval(owner: <indexed>, spender: <indexed>, value: 4)

---------------------------
```

Error: VM Exception while processing transaction: revert at Object.InvalidResponse (node\_modules/truffle-contract/node\_modules/web3/lib/web3/errors.js:38:16) at node\_modules/truffle-contract/node\_modules/web3/lib/web3/requestmanager.js:86:36 at node\_modules/truffle-provider/wrapper.js:134:9 at XMLHttpRequest.request.onreadystatechange (node\_modules/truffle-provider/node\_modules/web3/lib/web3/httpprovider.js:128:7) at XMLHttpRequestEventTarget.dispatchEvent (node\_modules/xhr2/lib/xhr2.js:64:18) at XMLHttpRequest.\_setReadyState (node\_modules/xhr2/lib/xhr2.js:354:12) at XMLHttpRequest.\_onHttpResponseEnd (node\_modules/xhr2/lib/xhr2.js:509:12) at IncomingMessage.<anonymous> (node\_modules/xhr2/lib/xhr2.js:469:24) at endReadableNT (\_stream\_readable.js:1055:12) at \_combinedTickCallback (internal/process/next\_tick.js:138:11) at process.\_tickCallback (internal/process/next\_tick.js:180:9)

[Vamsee](https://hashnode.com/@vamsee)

[Mar 26, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be#reply-5ab886bc17ffdb9314085414)

Here is the fixed/working code, thanks to advice from [github.com/OpenZeppelin/zeppelin-solidity/issues/…](https://github.com/OpenZeppelin/zeppelin-solidity/issues/584#issuecomment-376042522)

```
  it('Token transfer', async () => {
    const fromAccount = accounts[1]
    const toAccount = accounts[4]
    const transferLimit = 4000000000000000000
    const transferAmount = 3000000000000000000
    let ecoSystemBalance = await tokenInstance.balanceOf(fromAccount)
    assert.isAtLeast(ecoSystemBalance, transferLimit, 'From account balance should be atleast 4')
    await tokenInstance.approve(toAccount, transferLimit, {from: fromAccount})
    assert.equal(await tokenInstance.allowance(fromAccount, toAccount), transferLimit, 'Allowance from->to should be 4')
    console.log(`Attempting a transfer with ecoSystem balance of ${ecoSystemBalance}`)
    await tokenInstance.transferFrom(fromAccount, toAccount, transferAmount, {from: toAccount})
    assert.equal(await tokenInstance.balanceOf(toAccount), transferAmount, 'To account should have 3')
  })
```

[ka eliz](https://hashnode.com/@kaeliz)

[Mar 2, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a99c828e96b069606051bb7)

Hi Sandeep, thanks for your great post.

I am having problems when I try to test on Ropsten. I successfully passed Truffle test; but on

truffle migrate --network ropsten

I got this:

Running migration: 1\_initial\_migration.js

Deploying Migrations...

Error encountered, bailing. Network state unknown. Review successful transactions manually.

insufficient funds for gas \* price + value

I Tried to change gas value many times, but nothing happened.

Could you help me?

thanks

[Abe Rios](https://hashnode.com/@aberios)

[Mar 12, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a99c828e96b069606051bb7#reply-5aa69faae3b46e6c2a15d301)

I'm having the same issue deploying to TestNet. I get the message "The contract code couldn't be stored, please check your gas amount". Increasing gas doesn't seem to work, and if I increase it too much, exceed the max gas limit. Anyone find a solution this?

[Shubham Constacloud](https://hashnode.com/@ShubhamCloud)

[Mar 16, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a99c828e96b069606051bb7#reply-5aab92bb906922e006c5cfd8)

i figured out this issue by passing gas 4000000 and before deploy your contract please get some ether balance in your owner account using metamask ropsten test faucet, after that you will be to deploy contract without any error.

[Roman S](https://hashnode.com/@rom18)

[Mar 2, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a99abcde96b069606051b79)

How to manage ICO stage after contract is deployed?

Where can I find examples of using setCrowdsaleStage() and finish() functions?

[Martin Blanco](https://hashnode.com/@kaptincho)

[Mar 2, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a998fd3e96b069606051b35)

Now... Once the ico is finished, how can I see the balance of tokens that have been returned to the addresses that have participated?

```
web3.eth.getBalance(accounts[0]);
```

Shows me the eth balance, not the token balance.

[Martin Blanco](https://hashnode.com/@kaptincho)

[Mar 6, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a998fd3e96b069606051b35#reply-5a9e9ed4e96b0696060537e9)

I was looking and analyzing, to see the tokens you must make the query with the api webjs of ethereum making the call with your JSON ABI contract.

Load webjs api on html file first:

`<script src="web3.min.js"></script>`

then execute this JS example:

```
var web3 = new Web3(new Web3.providers.HttpProvider("http://RPCBlockchainIP:RPCBlockchainPort")); 
var erc20Abi = [Your JSON ABI Contract]; 
var tokenContract = web3.eth.contract(erc20Abi).at("Your Contract Token Address"); 
var tokenBalance = tokenContract.balanceOf.call("Your Account Address to Test"); 
console.log(tokenBalance);
```

[Tony](https://hashnode.com/@Tonytl)

[Feb 28, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9644ab0430f87244d3cacd)

Thank you Sandeep.

I found a little bit issue where after i bought every token in the PreICO, and start to buy the token in ICO, I couldn't get the token into my account. Does anyone know why

[Tony](https://hashnode.com/@Tonytl)

[Mar 5, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9644ab0430f87244d3cacd#reply-5a9dd463e96b0696060530fe)

Hi Martin, i understand that the ether go the vault during the ICO stage, but the investors should get their token in their account, which in this code it doesn't. After the PreICO limit hit, it returns the ether directly to the investor's wallet, without going to the ICO stage. Did i miss out anything?

[Martin Blanco](https://hashnode.com/@kaptincho)

[Mar 6, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9644ab0430f87244d3cacd#reply-5a9f1d1a0430f87244d401b3)

that is not written in the contract code, you must change the status of the contract manually by calling the function: "setCrowdsaleStage" to 1, using web3js and using owner account in metamask

[Shubham Constacloud](https://hashnode.com/@ShubhamCloud)

[Mar 8, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9644ab0430f87244d3cacd#reply-5aa1153b0430f87244d40f55)

Hello Martin Blanco, can you please explain in details how to call contract methods in ropsten test network. I have successfully done the PreICO but now i am stuck in start the ICO.

[David Alvarado](https://hashnode.com/@madebydiesel)

[Feb 21, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a8dba55dbacfbab306e6f77)

Does anyone else have an issue calling the "finish()" function? When I try to invoke it I get a "gas limit too high" error.. no matter what I try to set it at it won't accept, it fails... have tried using Mist to access the contract after it's deployed to Ropsen

[Martin Blanco](https://hashnode.com/@kaptincho)

[Mar 2, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a8dba55dbacfbab306e6f77#reply-5a99990ee96b069606051b65)

finish() call need 3 parameter address: "teamFund, ecosystemFund, bountyFund"

> `function finish(address _teamFund, address _ecosystemFund, address _bountyFund) public onlyOwner {`

[David Alvarado](https://hashnode.com/@madebydiesel)

[Mar 2, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a8dba55dbacfbab306e6f77#reply-5a999957e96b069606051b69)

Yes.. I've included those when calling the function, but it fails do to Gas limit no matter what I set it at

[Tony](https://hashnode.com/@Tonytl)

[Mar 13, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a8dba55dbacfbab306e6f77#reply-5aa7695c9026e896356a880d)

You have to use the creator account/address, in order to call the function

[brian](https://hashnode.com/@brian1)

[Feb 9, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a7da0192c654c204774a017)

Great write up, works perfectly. Well done! What is involved in getting this to mainnet, just changing the network?

[Anwar Shaikh](https://hashnode.com/@anwarsquarebiz)

[Mar 12, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a7da0192c654c204774a017#reply-5aa7087d9026e896356a8515)

If you are facing problem at step where you need to run truffle test in Windows cmd, then use power shell in windows it will let you run the test. As cmd open the file truffle.js in editor but power shell will run the code in truffle.js. If you want to know where to look for power shell refer this - [docs.microsoft.com/en-us/powershell/scripting/set…](https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-6)

[Anwar Shaikh](https://hashnode.com/@anwarsquarebiz)

[Mar 12, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a7da0192c654c204774a017#reply-5aa70a66e3b46e6c2a15d9dc)

Can you please have a tutorial on web3.js. Could not understand how to show the raised amount of eth.

[ChiragMaliwal](https://hashnode.com/@cmaliwal)

[Mar 13, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a7da0192c654c204774a017#reply-5aa7dc619026e896356a8d7b)

I am also looking for the same.

[David Alvarado](https://hashnode.com/@madebydiesel)

[Feb 7, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a7b2a9b8ca6f0b65f040a67)

Everything works great, thank you.. my question is once you deploy to Ropsten test network how do you go about interacting with the contract to call finish() ?

What are the ways to interact with the contract once it's on Ropsten?

Thanks.

[Sandeep Panda](https://hashnode.com/@sandeep)

[Feb 19, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a7b2a9b8ca6f0b65f040a67#reply-5a8af6bf473ee05c2872697b)

Hi David! Thanks for reading. Once you have the contract address you can interact with the contract using online [Remix compiler](https://remix.ethereum.org/) or [Mist](https://github.com/ethereum/mist/releases).

[David Alvarado](https://hashnode.com/@madebydiesel)

[Feb 19, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a7b2a9b8ca6f0b65f040a67#reply-5a8b3752473ee05c28726e92)

Hi Sandeep.. thanks for your response.. I have been able to access the contract via Mist and when I try to run the "finish" function it won't execute do to "gas limit" it seems to be requiring excessive amount and when I adjust down, it fails.. any ideas how to get around this or resolve this?.. Thank you again.

[Green Monster](https://hashnode.com/@GMCC)

[Feb 1, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a72a8459cc7099e7dbf35ec)

Also, for anyone else trying out this tutorial but are using the latest version of zeppelin-solidity, I have found the following changes helpful.

(1) In HashnodeToken.sol change the filepath to include the ERC20 folder

import 'zeppelin-solidity/contracts/token/ERC20/MintableToken.sol';

(2) If you are unable to deploy the contract because of a gas issue, try updating the gas amount in truffle.js to reflect the limit in ganache. "gas: 6721974"

Hope this helps someone!

[Geo](https://hashnode.com/@gravyplaya)

[Jun 4, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a72a8459cc7099e7dbf35ec#reply-5b150d51e722fbf03d0be223)

I still get the gas error when setting "gas: 6721974". It seems no matter what i try it will not work. Perhaps the error is misleading but I cant track down the cause.

[Gael Durand](https://hashnode.com/@gael)

[Aug 1, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a72a8459cc7099e7dbf35ec#reply-5b6213a19ed4e2bf786dd69d)

I've got the same problem as Geo. Any solution?
