Thursday, July 31, 2014

Build "Ethereal" -- the Ethereum GUI client, Go 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 Go (aka Golang) version of the Ethereum client.
It was much faster and easier than the C++ version.

Overview of the entire set-up process

  1. Get VM (Virtual Machine) set up
  2. Run the Go-Ethereum install script
  3. Connect to the permanent Go-Ethereum mining node
  4. Run a sample program
  5. How to update Go-Ethereum from GitHub

1. Get VM (Virtual Machine) set up

If you have already set up your VM, 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. Run the Go-Ethereum install script

Just run these three commands from the Terminal window (for Ubuntu 14.04 only):
cd ~/src
wget https://gist.githubusercontent.com/maran/2d69089ed5ea3f83fde8/raw -O install
chmod +x install
./install
This takes a while to complete, so invest some of this waiting-around-time into reading this article discussing the current debate over Bitcoin within the Austrian school of economics.

If you were unable to make the script work, then follow the original, more detailed instructions here.


3. Connect to the permanent Go-Ethereum mining node

When I ran ethereal out of the box it was unable to connect to any peers. So, as a result I couldn't mine any Ether, which prevented me from actually executing my test code.
To get around this problem, connect your client to the permanent Go Ethereum mining node that was set up for developers and testers like us.

The first time you execute Ethereal, run these command in the Terminal:
cd $GOPATH/src/github.com/ethereum/go-ethereum/ethereal && ethereal -seed=false

When the GUI appears, type Ctrl-P, and paste the following into the popup window and click 'Add':
107.178.217.2:30303
Next, press the 'Start mining' button on the lower-left. You should (gradually over time) start to see the number of Ether increase on the status bar at the bottom of the window.

In the future, whenever you run Ethereal again you can launch it by running this in the Terminal:

cd $GOPATH/src/github.com/ethereum/go-ethereum/ethereal && ethereal


If you have trouble with this, then read the original description here.


4. Run a sample program

Let's copy this sample program (written in Mutan) and paste it into Ethereal:
# Initialization
contract.storage[tx.origin()] = 10**20
exit compile {
    var to = this.data[0]
    var from = tx.origin()
    var value = this.data[1]
 
    if contract.storage[from] >= value {
        contract.storage[from] = contract.storage[from] - value
        contract.storage[to] = contract.storage[to] + value
    }
}

Press 'Send'. It will give you the address of the contract you just sent to the network.

Now that you know Ethereal works properly, exit Ethereal, exit the VM, and take another VirtualBox snapshot.
Name the snapshot "Go-Ethereum compiled".

5. How to update Go-Ethereum from GitHub

Run these commands to update Go-Etherum (and Ethereal):
go get -u github.com/ethereum/go-ethereum/ethereum
go get -u -a github.com/ethereum/go-ethereum/ethereal
Then launch Ethereal normally:
cd $GOPATH/src/github.com/ethereum/go-ethereum/ethereal && ethereal

Sunday, July 6, 2014

Set up a Virtual Machine for Ethereum Contract Development

Yesterday, my friend and I got got talking about setting and achieving goals. Then he sent me this great article titled, "Do things, tell people."

My whole life I've kept to myself too much. So, I just made a promise to myself that whatever I'm working on, I'm going to share it with as many people as possible.
If I notice I'm not talking to people, then maybe I need to start doing things that are driven by a burning desire!
So, in the spirit of telling people what I'm doing, here is a blog post that explains how I set up my VM (virtual machine) which I later used to install the Ethereum client.

There are already well written instructions on the Internet that explain how to set up the Ethereum client. However, when I tried to follow the instructions I clearly made some kind of bone-headed mistake because my system stopped booting and I had to re-install the operating system. 
So, I'm recording what I did to make the process reproducible.
Also, from now on, if I have enough hard drive space, I will always set up my build environments inside of a virtual machine (VM) so I don't have to re-install the OS.

Overview of the entire set-up process for 

  1. Install VirtualBox
  2. Install Ubuntu 14.04 in VirtualBox
  3. Export the VirtualBox setup to back it up as a "Basic Ubuntu Install


1. Install VirtualBox

My host OS is Ubuntu 14.04 and my VirtualBox guest OS will also be Ubuntu 14.04.
Why did I choose Ubuntu 14.04 as my guest OS? Because most of the instructions I saw that provide the easiest methods for getting stuff to work were targeted to 14.04 -- I'm taking the path of least resistance.

I did not install VirtualBox from the Ubuntu Software Center because in the past I have been unable to make USB ports work using that method.
Follow the helpful instructions at the end of this section.
(Note that when the instructions mention the 'Other Software' tab, you need to select the Software Center menu 'Edit > Software Sources'.)

Here are the instructions.

2. Install Ubuntu 14.04 in VirtualBox

Follow this link so you can download an ISO image of Ubuntu 14.04.

One mistake I made in a previous attempt was to install on an older build of Ubuntu -- just install the newest version, life is too short!

Next, launch VirtualBox and create a new VM.
Name the VM "Ethereum Dev".
Set memory size to a large value -- I chose 1024 MB out of a total of 32 GB.
Select 'Create a virtual hard drive now' -- and be sure to choose 'VMDK' for greater portability to other platforms.
Allow the virtual drive to be 'Dynamically allocated' so it uses less space and expands in size as you use it more.
I chose the maximum value of 2 TB for my hard drive because I have an enormous hard drive and the virtual drive doesn't actually grow in size until you use it.

This next paragraph turned out to be kind of important:
Set up the ISO image as a DVD drive (or insert the physical DVD into the drive) before launching the new VM. I tried doing it after launching and I had to delete the VM, scream into a pillow, and start over.

Launch the new VM and click 'Install Ubuntu' from the ISO image.
I check-marked 'Download updates while installing', then clicked 'Continue'.
Because any code I develop inside this VM will be posted for anyone to use on the Internet, I chose to not encrypt the installation, so I selected 'Erase disk and install Ubuntu'.
I also check-marked 'Use LVM with the new Ubuntu installation' just for the hell of it.
Click 'Install Now'.
I also selected 'Log in automatically' then proceeded into the installation.
While it's installing, read this article and think about how bitcoin might affect our future.
When it's done installing, click 'Restart Now'.

Another thing that turned out to be important:
I originally tried doing all of the remaining steps in this section in a different order but it failed miserably.
Stick to the steps below. I've done it three times in a row and so far it's worked every time, but cross your fingers just in case.

Inside of the VM, open a Terminal window (Ctrl-Alt-T) and run these commands:
sudo apt-get update && sudo apt-get upgrade
While it processes that command, take some time to process this article by L. Neil Smith.
Then enter this command in the Terminal:
sudo apt-get install virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
These programs will allow the desktop to re-size so it always fits the size of the VirtualBox window. But keep in mind that I see this functionality stop working on a regular basis. I'm able to get it working again by exiting the VM then re-booting the host OS.

Run these command:
sudo apt-get update && sudo apt-get dist-upgrade
While the VM is still running, select this VirtualBox menu (not the VM menu): Devices > Insert Guest Additions CD Image
Then click the 'Run' button. Then answer 'yes' to continue despite the system whining that something seems wrong.

At this point I had to re-boot the VM because the screen was too small so I couldn't access some of the buttons. Re-boot the VM by clicking the gear icon in the upper-right and choosing 'Shut Down'.
Click 'Start' to re-launch the VM again.

Inside of the VM, install git by clicking on the Ubuntu Software Center. (I'll assume you know how to do that already.)

Exit the VM window, but leave the VirtualBox Manager window open.
Click the 'Snapshots' button, then take a snapshot (Ctrl-Shift-S).
Name the snapshot "Ubuntu basic install".

3. Export the VirtualBox setup to back it up as a 'Basic Ubuntu Install'

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.
In the event you completely gox things, you can always recover this basic setup by choosing 'File > Import Appliance'.

What next?

Next you'll want to install one or more of the Ethereum clients. I will create a blog post for each one later.
I plan on installing the Go, C++ and Python clients just because I'd like to learn new stuff.
Below is some info that may help you choose which one to install.

I read somewhere that the Go version would eventually be dubbed the reference client (meaning that it would be used to generate the binary executables for the general public to use).
Also, at the present time only the C++ and Go clients are technically compatible with each other -- so I suppose that may mean the Python client is not as up-to-date?

But if you want to write programs for Ethereum in a specific language, then you need to understand that at some point in the future all three languages (LLL, Serpent and Mutan) will work on all the clients. But for now:
  • The Go-like language, which is called "Mutan", only runs on the the Go client.
  • The Python-like language, which is called "Serpent", only runs on the Python client.
  • The Lisp-like language, called "LLL", only runs on the C++ client.
If you're like me, I'd like to use the GUI (graphical user interface) instead of the CLI (command line interface) at first. When I understand things a little better I'll want to learn the CLI as well.
One area of confusion for me was the naming of the GUI clients:
  • The C++ GUI client is called "alethzero".
  • The Go GUI client is called "ethereal".
  • The Python client does not come as a GUI form, only as a CLI, and it's called "pyeth".