Blockchain Development Environment

The following instructions assumes Ubuntu 16.04 linux, but is similar for other versions of Linux (and MacOS). An Ubuntu server can be created from scratch by initializing an AWS EC2 instance. Note the free t2.micro does not have enough resources to run the blockchain. Instead, create at least a t2.medium instance with 16GiB volume attached. See here for basic instructions on Windows 10 installation.

Package Installation

Make sure the package manager has reference to the Ethereum repository and is up-to-date in basic Ethereum development packages

sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install curl git vim build-essential libssl-dev
sudo apt-get install software-properties-common

Then install Node.js for a Javascript runtime environment (best to use NVM):

curl -o- | bash
source ~/.profile
nvm install node

Use Node.js package manager to install Truffle, an Ethereum development framework, and Solidity, a high-level language for smart contracts

npm install -g truffle
npm install -g solc

Install the personal blockchain RPC client for testing and development (used to be called testrpc but has been renamed Ganache)

npm install -g ganache-cli

These optional installs could be useful with other development tools in the future, but can be installed later.

sudo apt-get install ethereum ##optional, installs geth
sudo apt-get install solc ##optional, installs C-version of solidity
npm install web3 ethereumjs-util ethereumjs-tx ###optional
sudo npm install -g express ###optional
sudo npm install web3-utils ###optional utilities

Testing the Installation

Test out installation with an example Truffle project, such as MetaCoin which comes with the Truffle distribution

mkdir MetaCoin
cd MetaCoin
truffle unbox metacoin
truffle compile
truffle develop

This will launch a simple test network and command line interface. It also creates 10 dummy user accounts with 100 dummy Ether each. For example, typing this command into the Truffle command line interface shows the initial balance on the first account.

truffle(development)> web3.eth.getAccounts().then(function(accounts) {return web3.eth.getBalance(accounts[0]);}).then(function(balance) {return web3.utils.fromWei(balance,'ether');}).then(function(ether) {return parseFloat(ether);})

The contract can be deployed into the (dummy) blockchain using the migrate command. Note this uses Ether, which can be confirmed by checking the balance on the default account after running migrate.

truffle(development)> migrate --reset
truffle(development)> web3.eth.getAccounts().then(function(accounts) {return web3.eth.getBalance(accounts[0]);}).then(function(balance) {return web3.utils.fromWei(balance,'ether');}).then(function(ether) {return parseFloat(ether);})

Exit out of Truffle using Ctrl-D.

Migrating to a Standalone Network

The Truffle develop option provides a quick way to debug a contract, but it is solely contained on the development computer. Any testing with a network and between computing nodes requires an actual network.

A good first step is to do this with a test network still completely on the development computer. Start the test network (ganache-cli) in another terminal (preferred, since various logs will be echoed to the screen) or run in the background with the ampersand


Truffle needs to be configured to make this work, edit the truffle.js in the MetaCoin directory to be as follows:

module.exports = {
networks: {
development: {
host: "",
port: 8545,
network_id: "*" // Match any network id

Then run Truffle and migrate the contract. This should give the same result as when using truffle develop

truffle console
truffle(development)> migrate --reset