Thursday, August 14, 2014

Build BitShares-X Client on Ubuntu 14.04

BitShares X was the first project from Invictus Innovations that I participated in.
For some reason Invictus Innovations creates binaries for their client software only for Mac and Windows.
Below are the instructions on how I set it up on Ubuntu 14.04.

Install prerequisite packages (including some that are not mentioned in the docs):

sudo apt-get update
sudo apt-get install cmake git libreadline-dev uuid-dev g++ libdb++-dev libdb-dev zip libssl-dev openssl build-essential python-dev autotools-dev libicu-dev libbz2-dev libboost-dev libboost-all-dev nodejs-legacy libgl1-mesa-dev libegl1-mesa-dev npm

Download BitShares X code from GitHub:

cd ~/src
git clone
cd bitsharesx

Go to this web page so you can get the latest release number (for example: 0.4.20):

git tag  #Note the exact name of the tag for that version
git checkout v0.4.20
git submodule init
git submodule update

Download and install Qt 5.3.1 for Linux 64-bit:

cd ~/src
chmod +x

Download and install Node.js v0.10.29:

cd ~/src
tar xzf node-v0.10.29-linux-x64.tar.gz
cd node-v0.10.29-linux-x64
export PATH=/home/$USER/src/node-v0.10.29-linux-x64/bin:$PATH

Install lineman and its dependencies in web_wallet folder using npm:

cd ~/src/bitsharesx/programs/web_wallet

(The next two commands take a few minutes to complete.)

sudo npm install -g lineman
sudo npm install

Configure using CMake:

cd ~/src
mkdir bitsharesx-build
cd bitsharesx-build
export CMAKE_PREFIX_PATH=/home/$USER/src/Qt/5.3/gcc_64/
cmake -DINCLUDE_QT_WALLET=ON ../bitsharesx

Make the web wallet first, and then the rest of the system -- note that there will be a lot of warnings -- just ignore all the warnings:

cd ~/src/bitsharesx-build
make buildweb

Run the Qt client to confirm that it works:

cd ~/src/bitsharesx-build/programs/qt_wallet && ./BitSharesX

The first thing you should do is export your wallet. It will be saved in the form of a .json file and the contents will be encrypted already.

To upgrade to the latest release of BitSharesX

First, delete the old build:

cd ~/src
sudo rm -rf bitsharesx

Then repeat the steps above in the section titled: "Download BitShares X code from GitHub"
Skip the sections for installing Qt and node.js.
Then continue following instructions above starting with the section "nstall lineman and its dependencies in web_wallet folder using npm".

If you have problems with any of the above, then refer to the original instructions here.

If BitSharesX never synchronizes completely

If you can launch BitSharesX and log in normally but it never completely synchronizes because it displays "Severe network problems | Last block is synced xx days old" at the bottom of the screen, then do the following:

  1. Using Ubuntu's GUI file browser, go to your Home folder.
  2. Copy the "BitShares X" folder and Paste it -- the new folder will be named "BitShares X (copy)" -- this is your backup in case things don't work properly.
  3. Open the "BitShares X" folder and delete everything except the "wallets" folder.
  4. Re-boot your VM.
  5. Launch BitSharesX -- it will take a while to respond. While you're waiting it will say "Not connected" in the lower right. Eventually it will start synchronizing... and that will take even longer because it will download the entire blockchain again.

Build BitShares-PTS Client on Ubuntu 14.04

Holding BitShares-PTS in your own private wallet is the only way you can use the "protoshares" cryptocurrency to gain access to fundraisers in Invictus Innovations projects, but the BitShares-PTS wallet is a pain to set up on Ubuntu.
Below is the process I followed to set up my BitShares-PTS wallet.

In the Terminal window type:
sudo apt-get install qt4-qmake libqt4-dev build-essential libboost-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libssl-dev libdb++-dev libminiupnpc-dev
cd ~/src
git clone

To build the CLI:
cd BitShares-PTS/srcmake -f makefile.unix

To build the GUI, first download Qt-Creator.

Then run these commands:
cd <folder-where-qt-file-was-saved>
chmod +x

Accept all the defaults when going through the GUI prompts and let it launch Qt Creator when it's done installing.

In Qt Creator:
File > Open File or Project
Select the file: ~/src/BitShares-PTS/
Press: Configure Project
On the left side press the green triangle icon to run BitShares-PTS.
The current status of the build should appear at the bottom right.
After a period of building it should launch BitShares-PTS GUI client -- exit the client right away because you need to make some additional changes first.

The client will not work unless you provide some valid peers to connect to, so type this in the Terminal:
cd ~/.bitshares-pts
gedit bitshares-pts.conf

Copy and paste this text inside of the file and save it:

After you exit BitShares-PTS (and Qt Creator), you can launch from the command line by typing:

If you get this message in the lower left of the BitShares-PTS client

"No block source available"

Then click: Help > Debug Window
Click Console tab.
And enter these commands into the edit box at the bottom of the window:
addnode add
addnode add
addnode add
addnode add

If you get this error message when you launch the BitShares-PTS client

"Error loading block database. Do you want to rebuild the block?"
then do this in the Terminal:
cd ~/src/build-bitshares-pts-Desktop_Qt_5_3_GCC_64bit-Debug
./BitShares-PTS --reindex

Saturday, August 2, 2014

Build "PyEth" -- the Ethereum command-line client, Python implementation

Please use the instructions at this page instead -- I was never able to get a return value from a contract using the setup described below.

I recently built the Python version of the Ethereum client (which does not come in GUI form, it only comes as a command-line tool).
With this version of the client you can run Serpent code.

Overview of the entire set-up process

  1. Set up VM
  2. Install pip
  3. Build pyeth
  4. Install pyethereum
  5. How to update pyethereum from GitHub

1. Set up VM

If you have already set up your VM (Virtual machine), then take a snapshot first in case something goes wrong.
If you have not already set up your VM, then follow the steps from this blog post.

2. Install pip

Download and note which folder you saved it in.

Then run these commands from the Terminal:
cd folder-where-you-downloaded-the-file
sudo python
If the above instructions did not work, then try the instructions here.

3. Build pyeth

(Note: I have not actually tested pyeth yet, but do these steps anyway in case subsequent steps depend on them.)

At the terminal type:

sudo apt-get install -y build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev curl python-dev
sudo pip install virtualenv
cd ~/src
sudo python
git clone
Download this file to ~/src:
At the terminal type:
sudo python
wget -O - | sudo python
cd pyethereum
sudo pip install -r requirements.txt
sudo python install

Delete the database, just in case it's an older version that doesn't match the software:
rm -fr ~/.pyethereum/statedb
Run PyEth for the first time -- remember, this is only a command-line program, there will not be a graphical interface. (Note that when it runs the very first time it might give you a warning message regarding .python-eggs):
If it seems to be running without issues, then press Ctrl-C to exit.
If you did get a python-eggs error, then enter this command to fix it:
chmod g-wx,o-wx ~/.python-eggs

4. Install pyethereum

Pyethereum allows you to call test contracts by calling them from python code.
Personally, I find this method of testing contracts to be very convenient.
Set up pyethereum:
cd ~/src/pyethereum
sudo python install
To interact with the Ethereum blockchain call:

5. Run a Serpent program on pyethereumNext, create a really simple contract that registers names -- much like namecoin -- and save it in the file "":
key =[0]value =[1]
# Key not yet claimedif not[key]:[key] = value   return(1)else:   return([0], 1)  # Key already claimed
Then, create a python program that invokes the contract. Save it in the file "":
#! /usr/bin/env python
from pyethereum import tester as t
def run_serpent():
    s = t.state()  #Initialize genesis block
    c = s.contract('')  #Initialize contract
    name = "george"
    locn = 45
    result = s.send(t.k0, c, 0, [[name, locn]])
    print "Claim name \"{}\"\n at location {}\n result = {}".format(name, locn, result)
    name = "george"
    locn = 20
    result = s.send(t.k0, c, 0, [[name, locn]])
    print "Claim name \"{}\"\n at location {}\n result = {}".format(name, locn, result)
    name = "harry"
    locn = 65
    result = s.send(t.k0, c, 0, [[name, locn]])
    print "Claim name \"{}\"\n at location {}\n result = {}".format(name, locn, result)

if __name__ == "__main__":
Then test the contract by calling the python script from bash:

5. How to update pyethereum from GitHub

When the Ethereum folks announce a new proof-of-concept, update your local copy by running this in a terminal window:
cd ~/src/pyethereum && git pull -u origin master
Now, let's build it:
curl | python
Test that the setup works by launching PyEth:

Build "Aleth Zero" -- the Ethereum GUI client, C++ implementation

Please use the instructions at this page instead -- I was never able to get a return value from a contract using the setup described below.

I just installed the C++ version of Ethereum.
I've tried to provide the simplest explanation I could below.

Overview of the Entire Set-up process

  1. Set Up VM
  2. Build Stuff that Ethereum Needs
  3. Build Ethereum Client
  4. Launch AlethZero to Test It
  5. Get Some (Fake) Ether
  6. Optional: Back Up VM
  7. Load Contract
  8. Call Contract
  9. Learn How to Write Contracts
  10. Get Latest Client From GitHub

1. Set Up VM

If you have already set up your VM (Virtual Machine), then take a snapshot first in case something goes wrong.
If you have not already set up your VM, then follow the steps from this blog post.

2. Build Stuff that Ethereum Needs

Below I've summarized all the commands I entered in a Terminal window -- inside of the VM.
Some of the steps below will take a while, so while you're waiting for those steps to complete, check out this article.

Here are the steps to build Ethereum:
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y build-essential g++-4.8 git cmake libgmp-dev libboost-all-dev automake unzip libtool libleveldb-dev yasm libminiupnpc-dev libreadline-dev scons libncurses5-dev qtbase5-dev qt5-default qtdeclarative5-dev libqt5webkit5-dev libcurl4-openssl-dev

I like to create a separate directory to store all my source code in before I begin:
mkdir -p ~/src

cd ~/src
git clone
cd cryptopp && sudo scons --shared --prefix=/usr

cd ~/src
git clone git://
cd libjson-rpc-cpp && git checkout v0.3.2
mkdir -p build && cd build && cmake .. && make
sudo make install
sudo ldconfig

3. Build Ethereum Client

In case there's a pre-existing incompatible blockchain, delete it:
rm -fr ~/.ethereum
Get the source code from GitHub:
cd ~/src
git clone
Now, let's build it:
cd ~/src/cpp-ethereum && git checkout develop
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release && make

4. Launch AlethZero to Test It

The C++ GUI client is called "AlethZero" (not "AlephZero").
After building the client software, test that it works by entering this command:
cd ~/src/cpp-ethereum/build/alethzero && ./alethzero
Wait a minute for the GUI to launch.

Click the button 'Go!' to connect to peers on the global test network.
Verify that you're connected to at least one peer by looking at the bottom of the client's GUI.

(The following info should not be necessary anymore, but here it is just in case: If after a minute or two you do not see any peers, then you'll have to hunt around in the Ethereum forums for an address that you can manually enter by selecting Network > Connect to peer. Just remember that the IP address you enter must always end with ":30303")

5. Get Some (Fake) Ether

First method - faucet:
Go to this website to get some free fake Ether to run your test programs with.
First, copy your address by double-clicking on an address in AlethZero's "Owned Accounts" sub-window, then paste into the web page and click the "Gimme Wei" button.

You may need to click the 'Refresh' button for your balance to refresh properly. I've noticed that Alethzero has a problem with not refreshing the GUI, so click 'Refresh' regularly.

Exit AlethZero, exit the VM, and take another VirtualBox snapshot.
Name the snapshot "Ethereum client compiled".

Second method - mine it:
Next, mine your own Ether by choosing menu: Debug > Force Mining.
Then click the button 'Mine'.

If the steps above did not work for you, then here are the original instructions from the Ethereum web page.

6. Optional: Back Up VM

Log out of the VM, but leave the main VirtualBox Manager window still running.
Choose menu: File > Export Appliance
Save it to an external drive if you have one available.

Now that you have a backup, you can import the "Ethereum Dev" VM onto any machine with VirtualBox installed.
(Be sure to check-mark 'Reinitialize the MAC address of all network cards' -- just in case you want several VMs on the same network -- at least that's what I read online somewhere.)

7. Load Contract

Eventually, all of Ethereum's contract languages will run on all the clients, but at the present time AlethZero only runs contracts written in LLL or Serpent.

Copy the following LLL contract and paste it into the 'Data' field in AlethZero (this contract simply multiplies a number by two):

(return 0 
            (set '_temp4_1 (mul (calldataload 0) 2))
            (return (ref '_temp4_1) 32)

Stop mining by clicking the 'Mine' button again (we're only stopping mining so we can easily identify our contract in the pending window).
Then click the button 'Execute'.
Look in the "Pending" sub-window and note the address of the contract (it will follow the word "Creates:").

Start mining by clicking the 'Mine' button again -- this will cause the "Pending" sub-window to clear out.
Now you can open the "Contracts" sub-window and double-click on the contract that begins with those same characters you noted earlier. Double-clicking copies the text of the address (yeah, I know that's not standard behavior).

8. Call Contract


9. Learn How to Write Contracts

All of this info is most certainly outdated already, but it's probably still worth looking at until we get newer info.

10. Get Latest Client From GitHub

When the Ethereum folks announce a new proof-of-concept, update your local copy by running this in a terminal window (this is the scorched earth approach and seems to work best):
cd ~/src && sudo rm -rf cpp-ethereum
Then run through the steps again in the section titled: "Build Ethereum Client".

Feel free to play around with AlethZero -- if you completely mess things up just restore the previous VM snapshot.