How to Deploy a Crowdsale Initial Coin Offering (ICO) to your own Private Testnet

We’ve been trying to deploy a Crowdsale Initial Coin Offering (ICO) Solidity contract to the Ethereum block chain for the better part of 2 months.

Code for an Initial Coin Offering Fund raise[/caption]

We’ve looked into the Open Zeppelins tutorials on How to Create Token an Initial Coin Offering using Truffle and Open Zeppelin. We were able to compile their Crowdsale ICO, but each time I went to perform ‘truffle migrate’, I encountered the dreaded “Out of Gas” error message that is the default error provided by Truffle’s migration code. This error tells you nothing. After a while you start to deduce that nothing is wrong with your TestRPC or private testnet config, instead not all of the code has been checked into Github…

With the Open Zeppelin tutorial, the deploy step is not specified. With many of the other ICO open source codebases in Github, the deploy step is not specified either. The deploy step of Truffle is arguably the most poorly documented portion of their project. The Truffle documentation provides you with a few sentences. Without an example on how to deploy, forget it.

That’s where AllCode comes in. We’ve checked in a version of a Crowdsale ICO that you can actually compile, deploy, execute, and even run unit tests on. You can find it here

In order to get this running on your local machine, you’ll need to take the following steps. Our advice is to install geth locally and configure your own private testnet using a custom genesis block, click here to learn how. The Open Zeppelin tutorial says that you can use TestRPC. I’d avoid TestRPC. When I use TestRPC, I start to get weird invalid opscode errors, which if you google around, point to issues with TestRPC. Our advice is to figure out how to build your own private testnet with a custom genesis block.

When working with Ethereum locally, I usually have four terminal shells open. This may seem excessive, but it’s not

The first terminal shell executes geth on your own private testnet locally

geth --networkid 200 --identity node1 --verbosity 3 --datadir=~/myBlockChain/node1 
--rpc --rpcapi 'web3,eth,net,debug' --rpcaddr "" --rpcport "8545" --rpccorsdomain "*"

The second terminal shell is used to communicate with geth via ipc. Why do I need to communicate with geth via ipc? The documentation is not the greatest here, but what I’ve discovered is that in order to write to the blockchain, you have to be 1) mining with an account and 2) the account that you are mining under should be unlocked. If your account is not mining nor unlocked, then you will start to encounter hangs and frustrating error messages.

Use the following for ipc,

geth attach /Users/joelgarcia/myBlockChain/node1/geth.ipc

To start mining, you’d type the following in the ipc terminal prompt

miner.setEtherbase ( personal.listAccounts[0] )

To unlock your account, you’d type the following in the ipc terminal prompt

personal.unlockAccount( personal.listAccounts[0] )

Now, in your third terminal window, you’d install Truffle and clone from the github repo. Next, you’d run the following in the root directory of your git clone.

truffle compile

Truffle compile will build the json files that are required to deploy the Solidity contracts to the block chain. The Truffle.js in the root directory will specify that you’re talking to localhost on 8545.

In the fourth terminal window, you’ll want to open up the file: /allcode-coin/migrations/2_deploy_contracts.js with vi. You’ll need to edit this file. You’ll need to have created 2 accounts via the ipc command personal.newAccount(). From those 2 accounts, you’ll want to include one of those addresses as the wallet and the other as the owner. Navigate down to the deploy code. Notice that the deploy code is populated. We’ll go through the deploy code, and the unit tests in our next blog post

Now return back to the third terminal window, and type

truffle migrate

Truffle migrate will actually attempt to deploy to your local testnet. Believe it or not. This should theoretically work on your private testnet. If it doesn’t, please reach out,

Like what you read? Give allcode a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.