Ethereum: Difference between revisions

From Leo's Notes
This page was last edited on 30 June 2017, at 05:05.
Line 132: Line 132:


=== Private Test Net ===
=== Private Test Net ===
To start your own test network with your own ether, install {{code|geth}} and then do the following:
To start your own test network with {{code|geth}}:


{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
$ mkdir /tmp/eth/70
$ mkdir /tmp/ethereum-testnet
$ geth console
$ geth account new
WARN [06-29|22:58:44] No etherbase set and no accounts found as default
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {ff8d6e640f66aa4dcfc0248bb0c6b30ff0f2f3ae}


## In geth console:
$ vi genesis.json
$ 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",
     "config": {
    "timestamp": "0x0",  
        "chainId": 1,
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",  
        "homesteadBlock": 0,
    "extraData": "0x634f727365",  
        "eip155Block": 0,
    "gasLimit": "0x8000000",
        "eip158Block": 0
     "difficulty": "0x400",  
     },
     "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",  
     "difficulty": "200000000",
     "coinbase": "0x3333333333333333333333333333333333333333",
     "gasLimit": "2100000",
     "alloc": {
     "alloc": {
  }
                "ff8d6e640f66aa4dcfc0248bb0c6b30ff0f2f3ae": { "balance": "100000000" }
    }
}
}


## then use the previous eth.accounts[0] value as the etherbase value.
$  ./geth --datadir /mnt/scratch/ethereum-testnet init genesis.json
## The datadir should be somewhere else.
INFO [06-29|22:59:03] Allocated cache and file handles        database=/mnt/scratch/ethereum-testnet/geth/chaindata cache=16 handles=16
geth --datadir="/tmp/eth/70" --etherbase="{should be input }" --genesis privatenet_genesis_block.json console
INFO [06-29|22:59:03] Writing custom genesis block
privatenet
INFO [06-29|22:59:03] Successfully wrote genesis state        database=chaindata                                    hash=112b5a…506029
}}
INFO [06-29|22:59:03] Allocated cache and file handles        database=/mnt/scratch/ethereum-testnet/geth/lightchaindata cache=16 handles=16
INFO [06-29|22:59:03] Writing custom genesis block
INFO [06-29|22:59:03] Successfully wrote genesis state        database=lightchaindata                                    hash=112b5a…50602
 
$ ./geth --datadir /mnt/scratch/ethereum-testnet --mine --networkid 1 console
> eth.coinbase
"0xff8d6e640f66aa4dcfc0248bb0c6b30ff0f2f3ae"
 
> miner.setEtherbase(eth.accounts[0])
true


Example:
> miner.start(1)
{{highlight|lang=terminal|code=
null
$ ./geth  --networkid 34093 --genesis ~/ethereum/genesis.json --datadir ~/ethereum --etherbase="0xdc9b165c433c8a6ae48713e8eae926767af0bca0" console
$ miner.start(1)
}}
}}


Then attach to the instance with:
You can attach using:
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
$ ./geth --networkid 34093 --genesis ~/ethereum/genesis.json --datadir ~/ethereum --etherbase="0xdc9b165c433c8a6ae48713e8eae926767af0bca0" --ipcpath ~/ethereum/geth.ipc attach
$ ./geth --datadir /mnt/scratch/ethereum-testnet --ipcpath ~/ethereum/geth.ipc attach
}}
}}



Revision as of 05:05, 30 June 2017

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

My address is 0xd2f887eda1b28c8714dbb2cf63a59f77fb68fb94

Clients

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

When starting geth, it will automatically start downloading the blockchain. It depends on UDP/30303. Ideally, the client should be accessible publicly via that port.

The default cache size used by geth is quite small, so for an initial sync run:

$ geth --datadir /path/to/ethereum-data --cache=1024

Whilst it is syncing, you can check the state of the client by starting and attaching an interactive console:

$ geth attach
> net.listening
true
> admin.peers
> eth.syncing

To create a private net, provide a custom --networkid value or provide a genesis json file with --genesis. While on the private net, you can create a new account and start mining.

Other things you may want to do are:

Task Command
Create an account. Similar to creating a new wallet.
> personal.newAccount("Write here a good, randomly generated, passphrase!")
Show account balance
> web3.fromWei(eth.getBalance(eth.coinbase), "ether")
Show account address
> eth.coinbase
## or
> eth.accounts[0]
Start CPU mining. Useful on testnets
> miner.setEtherbase(eth.accounts[0]) 
> miner.start()



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 geth:

$ mkdir /tmp/ethereum-testnet
$ geth account new
WARN [06-29

You can attach using:

$ ./geth --datadir /mnt/scratch/ethereum-testnet --ipcpath ~/ethereum/geth.ipc attach

Dapp Information

Ethereum enables the decentralized web (web3). A dapp, short for decentralized app, is like a web application built on this decentralized web. dapps can be written in HTML and make use of existing JS libraries while taking advantage of the new features offered by ethereum (like what?)

To get started developing, get remix:



Glossary

Because there are so many foreign terminology kicking around.

Term Definition
web3 A decentralized web. The 'next' iteration of the centralized web as it is (web2).
DAG Directed Acyclic Graph. A ~1GB dataset used by Ethash. Generated for eacah epoch (every 30,000 blocks or 100 hours). The generation of a new DAG takes a long time.
Target Block Time The target block time is 15 seconds.
Gas The amount of ether required to compute something on the virtual machine.
Gas limit ???
Gas Price How much transactions cost.

|}

See Also

Greeter contract tutorial

Contract Guide

DApp Tutorial