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.
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 "127.0.0.1" --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[/fusion_builder_column][fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="no" center_content="no" min_height="none"] ) miner.start()
To unlock your account, you’d type the following in the ipc terminal prompt
personal.unlockAccount( personal.listAccounts )
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 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 will actually attempt to deploy to your local testnet. Believe it or not. Your crowdsale Initial Coin Offering (ICO) is now deployed to your test network. This should theoretically work on your private testnet. If it doesn’t, please reach out, [email protected].
Joel Garcia has been building AllCode since 2015. He’s an innovative, hands-on executive with a proven record of designing, developing, and operating Software-as-a-Service (SaaS), mobile, and desktop solutions. Joel has expertise in HealthTech, VoIP, and cloud-based solutions. Joel has experience scaling multiple start-ups for successful exits to IMS Health and Golden Gate Capital, as well as working at mature, industry-leading software companies. He’s held executive engineering positions in San Francisco at TidalWave, LittleCast, Self Health Network, LiveVox acquired by Golden Gate Capital, and Med-Vantage acquired by IMS Health.