Ethereum: Difference between revisions

From Leo's Notes
This page was last edited on 30 June 2017, at 01:58.
No edit summary
Line 3: Line 3:
My address is 0xd2f887eda1b28c8714dbb2cf63a59f77fb68fb94
My address is 0xd2f887eda1b28c8714dbb2cf63a59f77fb68fb94


== Go-Ethereum (geth) ==
== Setup ==
There are a few clients that you can use.
 
=== Go-Ethereum (geth) ===
The Ethereum client written in Go.  
The Ethereum client written in Go.  


=== Setup ===
==== Setup ====
To compile geth, ensure that you have {{code|go}}, {{code|gcc}}, and {{code|make}} installed. Then run:
To compile geth, ensure that you have {{code|go}}, {{code|gcc}}, and {{code|make}} installed. Then run:
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
Line 16: Line 19:
{{code|geth}} will be compiled in {{code|build/bin/geth}}.
{{code|geth}} will be compiled in {{code|build/bin/geth}}.


=== Usage ===
==== Usage ====
==== Create an Account ====
===== Create an Account =====
  personal.newAccount("Write here a good, randomly generated, passphrase!")
  personal.newAccount("Write here a good, randomly generated, passphrase!")


==== Get Balance ====
===== Get Balance =====
  web3.fromWei(eth.getBalance(eth.coinbase), "ether")
  web3.fromWei(eth.getBalance(eth.coinbase), "ether")


==== Get my address ====
===== Get my address =====
  eth.coinbase
  eth.coinbase
or
or
  eth.accounts[0]
  eth.accounts[0]


==== Start CPU Mining ====
===== Start CPU Mining =====
  miner.setEtherbase(eth.accounts[0])  
  miner.setEtherbase(eth.accounts[0])  
  miner.start()
  miner.start()


== CPP-Ethereum (eth) ==
=== CPP-Ethereum (eth) ===
The official C++ version of the Ethereum client.
The official C++ version of the Ethereum client.


=== Setup Overview ===
==== Setup Overview ====
On a  Fedora 22 machine, you will need to:
On a  Fedora 22 machine, you will need to:
# Download and compile the most recent version of LLVM. The packaged version of LLVM available from the official repositories is only version 3.7.
# Download and compile the most recent version of LLVM. The packaged version of LLVM available from the official repositories is only version 3.7.
Line 48: Line 51:
   leveldb-devel leveldb-devel pocl
   leveldb-devel leveldb-devel pocl


==== Build LLVM 3.8 ====
===== Build LLVM 3.8 =====
  git clone http://llvm.org/git/llvm.git
  git clone http://llvm.org/git/llvm.git
  cd llvm
  cd llvm
Line 56: Line 59:
  make install
  make install


==== Build libjson-rpc-cpp ====
===== Build libjson-rpc-cpp =====
  git clone https://github.com/cinemast/libjson-rpc-cpp
  git clone https://github.com/cinemast/libjson-rpc-cpp
  cd libjson-rpc-cpp
  cd libjson-rpc-cpp
Line 67: Line 70:
  sudo ldconfig
  sudo ldconfig


==== Build Ethereum ====
===== Build Ethereum =====
You may want to make a symlink for llvm/include/llvm-c and llvm/include/llvm in /usr so that the cmake files can find it. Defining LLVM_DIR is not sufficient.
You may want to make a symlink for llvm/include/llvm-c and llvm/include/llvm in /usr so that the cmake files can find it. Defining LLVM_DIR is not sufficient.


Line 76: Line 79:
  LLVM_DIR=/opt/llvm/include CMAKE_PREFIX_PATH=/opt/llvm/include:/opt/Qt5.5.0/Tools:/opt/Qt5.5.0/5.5/gcc_64/ cmake -DCMAKE_INSTALL_PREFIX=/opt/ethereum ..
  LLVM_DIR=/opt/llvm/include CMAKE_PREFIX_PATH=/opt/llvm/include:/opt/Qt5.5.0/Tools:/opt/Qt5.5.0/5.5/gcc_64/ cmake -DCMAKE_INSTALL_PREFIX=/opt/ethereum ..


== Other Topics ==
== Other ==
=== Backing up your key ===
=== Backing up your key ===
Copy the ~/.ethereum/keystore as a backup. It contains your encrypted key. Also, don't forget your passphrase.
Copy the {{code|~/.ethereum/keystore}} as a backup. It contains your encrypted key. Also, don't forget your passphrase.


=== Private Test Net ===
=== Private Test Net ===
To start your own test network with your own ether, install geth and then do the following:
To start your own test network with your own ether, install {{code|geth}} and then do the following:
 
{{highlight|lang=terminal|code=
$ mkdir /tmp/eth/70
$ geth console


<syntaxhighlight lang="text">
## In geth console:
mkdir /tmp/eth/70
$ personal.newAccount('password')
geth console
$ eth.accounts[0]
personal.newAccount('password')
## you can check the eth.accounts[0] address, copy it and memo to somewhere
eth.accounts[0]
## control + c then escape from geth console.


// you can check the eth.accounts[0] address, copy it and memo to somewhere
// control + c then escape from geth console.


// next make the private net genesisblock json file.
## next make the private net genesisblock json file.
vim privatenet_genesis_block.json  
vim privatenet_genesis_block.json  
// this is my sample of testnet genesis block json thank you @karalabe san
 
## this is my sample of testnet genesis block json
{
{
     "nonce": "0xlitebeefdeadbeef",
     "nonce": "0xlitebeefdeadbeef",
Line 107: Line 113:
   }
   }
}
}
// then use the previous eth.accounts[0] to the {should be input } place.
 
## then use the previous eth.accounts[0] value as the etherbase value.
## The datadir should be somewhere else.
geth --datadir="/tmp/eth/70" --etherbase="{should be input }" --genesis privatenet_genesis_block.json console
geth --datadir="/tmp/eth/70" --etherbase="{should be input }" --genesis privatenet_genesis_block.json console
privatenet
privatenet
</syntaxhighlight>
}}


Example:
Example:
Line 118: Line 126:
Then attach to the instance with:
Then attach to the instance with:
  ./geth  --networkid 34093 --genesis ~/ethereum/genesis.json --datadir ~/ethereum --etherbase="0xdc9b165c433c8a6ae48713e8eae926767af0bca0" --ipcpath ~/ethereum/geth.ipc attach
  ./geth  --networkid 34093 --genesis ~/ethereum/genesis.json --datadir ~/ethereum --etherbase="0xdc9b165c433c8a6ae48713e8eae926767af0bca0" --ipcpath ~/ethereum/geth.ipc attach
== Dapp Information ==
TBA


== See Also ==
== See Also ==

Revision as of 01:58, 30 June 2017

Ethereum is a crypto platform for running smart contracts and exchanging Ether.

My address is 0xd2f887eda1b28c8714dbb2cf63a59f77fb68fb94

Setup

There are a few clients that you can use.

Go-Ethereum (geth)

The Ethereum client written in Go.

Setup

To compile geth, ensure that you have go, gcc, and make installed. Then run:

$ git clone https://github.com/ethereum/go-ethereum
$ cd go-ethereum
$ make geth

geth will be compiled in build/bin/geth.

Usage

Create an Account
personal.newAccount("Write here a good, randomly generated, passphrase!")
Get Balance
web3.fromWei(eth.getBalance(eth.coinbase), "ether")
Get my address
eth.coinbase

or

eth.accounts[0]
Start CPU Mining
miner.setEtherbase(eth.accounts[0]) 
miner.start()

CPP-Ethereum (eth)

The official C++ version of the Ethereum client.

Setup Overview

On a Fedora 22 machine, you will need to:

  1. Download and compile the most recent version of LLVM. The packaged version of LLVM available from the official repositories is only version 3.7.
  2. Git clone v0.4.1 branch of the libjson-rpc-cpp code base. Versions higher may not compile. The most recent version fails due to dependency issues. Install to /usr or /opt/
  3. Install QT5.5 from the official website using their binary blob installer. The official repository does not have QT5 webengine. Neither does the official source.
  4. Compile ethereum using the dependencies installed above.

Some dependencies:

yum -y install  libffi-devel cryptopp cryptopp-devel \
  argtable argtable-devel libmicrohttpd libmicrohttpd libmicrohttpd-devel \
  cmake jsoncpp-devel jsoncpp gmp-devel \
  leveldb-devel leveldb-devel pocl
Build LLVM 3.8
git clone http://llvm.org/git/llvm.git
cd llvm
mkdir build ; cd build
../configure --prefix=/opt/llvm --enable-libffi
make -j 8
make install
Build libjson-rpc-cpp
git clone https://github.com/cinemast/libjson-rpc-cpp
cd libjson-rpc-cpp
git checkout tags/v0.4.1
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make
sudo make install
sudo ldconfig
Build Ethereum

You may want to make a symlink for llvm/include/llvm-c and llvm/include/llvm in /usr so that the cmake files can find it. Defining LLVM_DIR is not sufficient.

git clone ethereum-cpp
cd ethereum-cpp
mkdir build
cd build
LLVM_DIR=/opt/llvm/include CMAKE_PREFIX_PATH=/opt/llvm/include:/opt/Qt5.5.0/Tools:/opt/Qt5.5.0/5.5/gcc_64/ cmake -DCMAKE_INSTALL_PREFIX=/opt/ethereum ..

Other

Backing up your key

Copy the ~/.ethereum/keystore as a backup. It contains your encrypted key. Also, don't forget your passphrase.

Private Test Net

To start your own test network with your own ether, install geth and then do the following:

$ mkdir /tmp/eth/70
$ geth console

## In geth console:
$ personal.newAccount('password')
$ eth.accounts[0]
## you can check the eth.accounts[0] address, copy it and memo to somewhere
## control + c then escape from geth console.


## next make the private net genesisblock json file.
vim privatenet_genesis_block.json 

## this is my sample of testnet genesis block json
{
    "nonce": "0xlitebeefdeadbeef",
    "timestamp": "0x0", 
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 
    "extraData": "0x634f727365", 
    "gasLimit": "0x8000000", 
    "difficulty": "0x400", 
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", 
    "coinbase": "0x3333333333333333333333333333333333333333",
    "alloc": {
   }
}

## then use the previous eth.accounts[0] value as the etherbase value.
## The datadir should be somewhere else.
geth --datadir="/tmp/eth/70" --etherbase="{should be input }" --genesis privatenet_genesis_block.json console
privatenet

Example:

./geth  --networkid 34093 --genesis ~/ethereum/genesis.json --datadir ~/ethereum --etherbase="0xdc9b165c433c8a6ae48713e8eae926767af0bca0" console
miner.start(1)

Then attach to the instance with:

./geth  --networkid 34093 --genesis ~/ethereum/genesis.json --datadir ~/ethereum --etherbase="0xdc9b165c433c8a6ae48713e8eae926767af0bca0" --ipcpath ~/ethereum/geth.ipc attach


Dapp Information

TBA

See Also

Greeter contract tutorial

Contract Guide

DApp Tutorial