Ethereum: Difference between revisions

From Leo's Notes
This page was last edited on 30 June 2017, at 07:41.
Line 232: Line 232:


To get started developing, get remix:
To get started developing, get remix:
* https://theethereum.wiki/w/index.php/Remix
Not to be confused with: (WTF??)
* https://github.com/ethereum/remix
* https://github.com/ethereum/remix


Guides:
* https://dappsforbeginners.wordpress.com/tutorials/your-first-dapp/
* https://dappsforbeginners.wordpress.com/tutorials/your-first-dapp/
* https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2
* https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2
Examples:
https://github.com/pipermerriam/ethereum-alarm-clock
http://etheria.world/howto.html


== Glossary ==
== Glossary ==

Revision as of 07:41, 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()
Show your highest block number
> web3.eth.blockNumber
Show your sync status
> eth.syncing



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|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}

$ vi genesis.json
{
    "config": {
        "chainId": 1,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "difficulty": "200000",
    "gasLimit": "2100000",
    "alloc": {
                "ff8d6e640f66aa4dcfc0248bb0c6b30ff0f2f3ae": { "balance": "100000000" }
    }
}

$ geth --datadir /mnt/scratch/ethereum-testnet init genesis.json
INFO [06-29|22:59:03] Allocated cache and file handles         database=/mnt/scratch/ethereum-testnet/geth/chaindata 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=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 --networkid 1 console
> eth.coinbase
"0xff8d6e640f66aa4dcfc0248bb0c6b30ff0f2f3ae"

> miner.setEtherbase(eth.accounts[0])
true

> miner.start(1)
null
INFO [06-29|23:21:49] Commit new mining work                   number=1 txs=0 uncles=0 elapsed=317.301µs
INFO [06-29|23:21:49] Successfully sealed new block            number=1 hash=b30264…b9e94d
INFO [06-29|23:21:49] 🔨 mined potential block                  number=1 hash=b30264…b9e94d
INFO [06-29|23:21:49] Commit new mining work                   number=2 txs=0 uncles=0 elapsed=311.3µs
INFO [06-29|23:21:51] Successfully sealed new block            number=2 hash=a9e1ba…136f08
INFO [06-29|23:21:51] 🔨 mined potential block                  number=2 hash=a9e1ba…136f08
INFO [06-29|23:21:51] Commit new mining work                   number=3 txs=0 uncles=0 elapsed=286.197µs
INFO [06-29|23:22:01] Successfully sealed new block            number=3 hash=df146e…b51ba3
INFO [06-29|23:22:01] 🔨 mined potential block                  number=3 hash=df146e…b51ba3

To have multiple nodes on your new blockchain, you will need to use the bootnode utility that is bundled with go-ethereum. If you don't see it, run make all or download their binaries.

On a separate host that will act as the bootnode server:

## Generate a new key
$ bootnode --genkey=boot.key

## Start the service on 10.1.1.9:30301 (your IP:Port)
$ bootnode --nodekey=boot.key -verbosity 9 -addr 10.1.1.9:30301
self=enode://6e297235e51c000b0f5e3f6adb94759e51fee2402da6ce9a4086a98038e70955161583a0d199ccb3b688ef1eb7d10344749bd3dc86af52b6d52fc413ebbd7eb6@10.1.1.9:30301

You may want to define the addr parameter since these binaries for some reason defaults to IPv6 even though it isn't enabled on the server (WTF?). (Side note: I *think* when it binds to [::] it also listens on IPv4.). It's also important to run this bootnode on a separate server because local geth instances won't talk to it properly (another WTF?) even when the specified --bootnodes uses 127.0.0.1 or the local IP address (and it's not because of the firewall or routing either. It's just royally messed up).

With the bootnode set up, you can start the Ethereum nodes with the --bootnodes parameter set to the enode value that was printed by thte bootnode service.

$ geth --datadir /mnt/scratch/ethereum-testnet --bootnodes "enode://6e297235e51c000b0f5e3f6adb94759e51fee2402da6ce9a4086a98038e70955161583a0d199ccb3b688ef1eb7d10344749bd3dc86af52b6d52fc413ebbd7eb6@10.1.1.9:30301" --networkid 139 --rpc   --rpccorsdomain "*"   console

Troubleshooting

If your nodes are not seeing each other:

  1. Check the bootnode service. It should show the nodes pinging.
  2. On the console, run admin.nodeInfo.protocols. Ensure that the genesis and network values are the same.


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:

Not to be confused with: (WTF??)

Guides:


Examples: https://github.com/pipermerriam/ethereum-alarm-clock http://etheria.world/howto.html

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