Starting with Ethereum Dapps Development (Environment, Config and IDE)
When I looked into the world of blockchain and its capacity to mint money, I really wanted to jump into it and start developing Apps on it. I looked up the web for guides and they were pretty simple and straightforward like clicking the buttons on the menu and you are ready to write code.
So as per the Guides, I need to do following things to setup my environment:
- Install Geth and Mist. That's your Etherium Node and Your Dapps browser/Wallet/IDE. It was simple. Go to their website and download and install them. That's it.
- Connect to a test net. Before running your code to the main production blockchain (Homestead) with real ethereum, you should test your code on a test net (like Roposten, Rinkeby or local blockchain) with test Ethereum Coins which you can mine quickly or get free of cost from a Faucet.
In the second part, it seems simple but it's really fussy because if geth downloads and syncs the whole blockchain before you can do anything and to achieve that, I have to left my computer to do the sync for a few hours and it reached 98.5%. Close enough. In next 10 minutes to went down to 96%. Yes. you read it right. After downloading for further 10 minutes, it reduced down to 96%. Technically it's correct as in that 10 minutes, the ethereum blockchain size also increased and based on what I downloaded so far was only 96% of that. That's fine for a production node which is expected to run 24 hours non-stop and won’t be stopped after the sync. But for a development environment, it's not feasible as you can’t come to you machine to do the development and sit there waiting hours for the sync to complete before you see you test ethereum balance.
After reading and trying a lot of articles, stackoverflow answers I was able to spin up a fresh blockchain and mine coins on that too. so you are ready to develop app right away as soon as you have first 5 Ether in you account.
I just ran the following commands in terminal to get that running:
geth init --datadir ./data custom-genesis.jsonThis will create the blockchain and put all the blockchain data in data folder same folder where you run the command.
The custom-genesis.json I used is :
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "0x1",
"gasLimit": "2100000",
"alloc": {}
}After this you are good to run Geth to run as node. To do so, just the the following command in the same folder.
geth --dev --identity "MyAwesomeBlockChain" --rpc --rpcport "8000" --rpccorsdomain "*" --datadir "./data" --port "30304" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1900 --nat "any" consoleUsing --dev is a magical key parameter which lets you process the transactions on your local. Without this, your geth node will keep looking for another peer node which does not exists hence will never reach the state of being fully synced. Without this your transactions will be submitted but will never be mined.
You can get more information on https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options.
Now your Geth Console is running and you are on the command prompt of geth. That “console” parameter in the command caused it.
Mining Test Coins
To mine test coins, you need a EtherBase Account. All you need is just the address which will be used to store the mined Coins. You can use any approach to do this. Just Open Mist/EthereumWallet and it should show Private on top right of the splash screen informing you that you Mist/EthereumWallet is connected to your local Geth node.
Create an Account from there and copy the Address.
Come back to geth console and type in the follwing command:
> miner.setEtherbase('your ethereum account address you just created');This will set the Ether base account for mining. After this start mining with the following command:
> miner.start(1)The 1 passed as parameter means number of threads to be used for mining. You can pass nothing to create unlimited threads for mining but I won't recommend it.
Now you should be able to see mining happening and once a block is mined, you will get your balance updated in your wallet.
To stop mining, just type the following command to stop the miner.
> miner.stop()To process your transactions and execute your contracts, you need to be in mining state.
Beyond this point, you can use https://www.myetherwallet.com/ to pont to you local node and run contracts or just use Mist.
Mist also provides an IDE for Solidity (The programming language of Ethereum) from develop menu on top or goto contracts tab of the wallet.
Hope this speeds up your environment setup time. Keep checking here for the next post on creating a Dapp.
Till then happy mining.
