-
Notifications
You must be signed in to change notification settings - Fork 10
Home
Ethereum dApps have two key components: the on-blockchain code that is used for high security guarantees on a public or private blockchain (server-like), and the local front ends that provide user interface and off-blockchain functionality to the user (client-like).
In this guide we provide basic instructions for getting started with dApp development by using the Geth blockchain client for interacting with the blockchain and MeteorJS to create an HTML5 front end that interacts with it via Javascript APIs. For further details on each component of this stack, or to explore some of the many other possibilities for developing dApps on Ethereum, feel free to consult the following links as a reference:
- Frontier Guide
- Ethereum Development Tutorial
- Ethereum JavaScript API
- Building Ethereum (Go client)
- Ethereum Forums
- List of dApps; some are open-source.
Let's begin by getting our stack set up. Although developing dApps that use the public Ethereum blockchain is in some sense no different than using a private blockchain or a local test blockchain, a few practical factors make it easier to start with controlled environments. This guide will show you how to set up your own local blockchain for testing so that you don't have to worry about things like obtaining ether to pay for blockchain space. During the hackathon itself, we will also make available a shared private blockchain on a designated IP address so that different teams and machines can easily interoperate or take advantage of shared tools.
A variety of easy installation methods are available, depending on your OS.
To install on linux (Ubuntu) run the follow commands:
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
Mac: You will need the "Homebrew" packages.
brew tap ethereum/ethereum
brew install ethereum
Windows: You will need to install the chocolatey.org system, and then install Geth from its package manager. From the PowerShell:
PS\:> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
and then
choco install geth-stable
The first thing you should do after installation is to accept the disclaimer and set up a local ethereum account. You can do both by running:
geth account new
After accepting the disclaimer, you will be asked to enter a password. A full set of geth commands can be found by typing geth --help. For our purposes, the next step is to run the console with some options that will create a local testing node and start mining some test ether:
geth --rpc --rpcaddr="0.0.0.0" --rpccorsdomain="*" --mine --unlock=0 --verbosity=5 --maxpeers=0 --minerthreads="4"
On the first instantiation this will autogenerate a DAG file, which will take about 5 to 10 minutes to create; once generated it will be reused for future instances of geth on your system. After typing in your account password you will have a local node that is serving http://localhost:3000, but you can change the address, or connect to another system on your network by changing the --rpcaddr="x.x.x.x" value. Note that after you've mined a few blocks you can stop the process ctl+z and restart without the --mine option.
Note that the default console has a high level of verbosity, and will show information about blockchain synchronization and downloading operations. To move such output to a text file and out of the console display screen, use geth console 2>> geth.log
For our first dApp example we will use Geth and MeteorJS. If MeteorJS isn't already installed, do so now:
Linux & Mac: To install meteor from your terminal, run curl https://install.meteor.com/ | sh from the terminal.
Windows: Download the binary: https://install.meteor.com/windows
To start using a dApp we can grab one from github. Let's try the following example. From the terminal or command prompt:
mkdir dapps
cd dapps
git clone https://github.com/SilentCicero/meteor-dapp-boilerplate.git
cd meteor-dapp-boilerplate
cd apps
meteor
In a separate window make sure that you have your geth rpc instance (described above) running in the background. From the browser now go to http://localhost:3000 to view this app in action. This is a simple app: it just shows the current ether balances of your local wallets.
There are two main approaches here: host your own compiler, or use an online version. Ethereum has a nice walkthrough for writing your first contract, and instructions for compiling that using solc or an online solidity compiler. Please read: https://github.com/ethereum/go-ethereum/wiki/Contract-Tutorial. This page also includes several excellent examples of smart contracts: greeter, crypto coin, crowdfunder, and a decentralized democracy system.
For simplicity, when it comes to compiling your apps we recommend using an online compiler (run locally or remotely): Cosmo http://cosmo.to/ or RealTime Solidity Compiler https://chriseth.github.io/browser-solidity/.
A private network is an ethereum blockchain with trusted nodes, and is usually operated within a single organization that wants to ensure the data written to the blockchain is not accessible or viewable outside of the organization (such as a bank). For instructions on setting up a private blockchain see https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster. For a discussion on the nature of private and consortium blockchains, see https://blog.ethereum.org/2015/08/07/on-public-and-private-blockchains/,
Note that for the hackathon, a single node (described above) is fine.