Monday, March 2, 2015

Develop Solidity Contracts on PoC-8

This is the fastest setup I could come up with that allows you to learn by doing.
This is for learning how to develop Ethereum contracts (not for developing Ethereum itself).

Set up the VM -- you only need to perform these steps one time

  • Add this to your ~/.bashrc file:
    export GOPATH=$HOME/go
    export PATH=$PATH:$GOPATH/bin
    export PATH=$PATH:/usr/local/go/bin
  • Close & re-open bash window.
  • Download the go installation file.
  • cd path-of-downloaded-file
    sudo tar -C /usr/local -xzf downloaded-file
  • sudo add-apt-repository -y ppa:mercurial-ppa/releases
    sudo apt-get install -y mercurial g++
    libgmp-dev libreadline-dev
  • go get
    go get

    cd ~/go/src/
    git checkout develop
    godep go install -v ./cmd/ethereum
  • ethereum account new
    (and enter a passphrase)
  • Take a snapshot of the VM. Name it: "go-ethereum develop branch".

    • Take a snapshot of the VM. Name it: "chrome browser". 

    • Install ethereum.js, this is necessary to make your JavaScript communicate with your contracts.
    • Take a snapshot of the VM. Name it: "ethereum.js".

    • Install a web server (so we can access the go-ethereum clients):
      (Substitute yellow highlights with appropriate info.)

      Download XAMPP web server from here.

      cd path-where-xampp-was-downloaded
      chmod 755 xampp-filename
      sudo ./xampp-
      Accept all defaults when installing XAMPP.
    • Make the web server launch at boot-up every time:
      sudo ln -s /opt/lampp/lampp /etc/init.d/lampp
      sudo update-rc.d lampp start 80 2 3 4 5 . stop 30 0 1 6 .
    • Take a snapshot of the VM. Name it: "xampp web server".

    • Get the files that will be served up:
      mkdir -p ~/src && cd ~/src

      mkdir -p ~/src/gists && cd ~/src/gists

      git clone

      git clone

      sudo mkdir -p /opt/lampp/htdocs/dev

      npm install bignumber.js
      sudo cp -R
      npm install ethereum.js
      sudo cp ~/node_modules/ethereum.js/dist/*.js /opt/lampp/htdocs/dev

      sudo cp ~/src/gists/2b57ad41419908cf6b8c/balance.html /opt/lampp/htdocs/dev

      sudo cp ~/src
      /gists/a9b10d3c58f7f434c0f1/contract.html /opt/lampp/htdocs/dev 
    • Take a snapshot of the VM. Name it: "files to be served". 

    • sudo add-apt-repository -y ppa:ethereum/ethereum-qt
    • Build the develop branch of cpp-ethereum -- while following the build instructions, if any issues crop up (such as packages held back, unable to upgrade, etc), then address them first before proceeding.
    • sudo ln -s ~/src/cpp-ethereum/build/eth/eth /usr/bin/eth
    • sudo ln -s ~/src/cpp-ethereum/build/alethzero/alethzero /usr/bin/alethzero
    • Take a snapshot of the VM. Name it: "build cpp-ethereum develop branch".

    • Install cpp-ethereum from the Ubuntu PPA (so you can use solc, the Solidity compiler):
      sudo add-apt-repository -y ppa:ethereum/ethereum-qt
      sudo add-apt-repository -y ppa:ethereum/ethereum

      sudo apt-get dist-upgrade -y &&
      sudo apt-get update -y
      sudo apt-get install -y cpp-ethereum
    • Take a snapshot of the VM. Name it: "cpp-ethereum ppa".

    • From the Terminal, run the GUI client:
    • Make sure this menu item is check-marked:
      Debug > Force Mining
    • Also, make sure this menu item is check-marked:
      Debug > Use Private Chain...
      (Enter the name for your private chain as "PrivateChain".)
    • Exit Ubuntu and take a snapshot of the VM. Name it: "Local Testnet".
    • From now on, every time you launch AlethZero these settings should already be set this way.
    • Take a snapshot of the VM. Name it: "alethzero settings". 

    • wget -O - | sudo python
    • git clone
    • cd pyethereum && python install

    Launch the tools that allow us to start developing smart contracts

    • Close all programs and re-boot the VM.
      (The web server automatically launches at boot-up.)
    • From a Terminal window, run:
      Minimize AlethZero to put it in the background.
    • From a Terminal window, run:
      ethereum account(and copy the address that appears in curly braces -- edit the address by removing every "0x" that occurs prior to each two-digit hex value. So, for example, the address "0x7f0xe00x01..." needs to be changed to "7fe001...")
    • ethereum --mine --rpc --unlock=address:password
      Wait for it to generate DAG -- this takes a long time.
      DAG generation is done when it displays messages: "Hash rate: x Khash", where x is non-zero -- this also takes a long time.
    • Launch the Chrome browser and go to:
    • Click the button "watch balance"
      If it displays a non-zero balance, then you have successfully communicated from a JavaScript program to a contract on Ethereum!
    • Continue with steps 5 through 8 in this forum posting here -- but remember that you must wait at least 12 seconds after loading each contract before you can interact with it.

      To compile solidity code, you can either use the web-based compiler you bookmarked earlier or you can call solc as follows:
      solc --input-file mySource.sol --json-abi file --binary file
      (two files will be created that contain the abi and binary info respectively.)

      Every time you create a contract from JavaScript you must: (1) Confirm a popup window from AlethZero that asks you to "Reject" or "Allow" the contract -- click on "Allow". (3) Open AlethZero and note the first few characters of the pending contract. (4) In AlethZero, click "Mine" then click "Go" and wait for the pending contract to become a contract. (5) Go back to the Chrome browser and continue to interact with the contract.

    No comments:

    Post a Comment