Ethereum-Geth


Install:

# dev
$ yum -y install epel-release golang gmp-devel
$ apk --update add --no-cache make gcc musl-dev linux-headers git

# geth
$ git clone https://github.com/ethereum/go-ethereum
$ cd go-ethereum && make geth
$ cp -p build/bin/geth /usr/local/bin/.

Quick Start:

# Initialize
$ geth --datadir /data init /data/genesis.json

# Run
# with console
$ geth --networkid 1234 --nodiscover --maxpeers 0 --datadir /data console 2>> /data/geth.log
# background with HTTP-RPC
$ nohup geth --networkid 1234 --nodiscover --maxpeers 0 --datadir /data --rpc 2>> /data/geth.log &

# Attach
$ geth attach ipc:/data/geth.ipc
$ geth attach rpc:http://localhost:8545

> personal.newAccount("password1")
> eth.getBalance(eth.accounts[0])
> personal.unlockAccount(eth.accounts[0], "password1")

> miner.start(1)
> miner.stop()

> eth.blockNumber

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei("1", "ether")})

Initialize for Test:

file: genesis.json
  edit: |
    {
        "config": {
            "chainId": 1234,
            "homesteadBlock": 0,
            "eip155Block": 0,
            "eip158Block": 0
        },
        "nonce": "0x0000000000000042",
        "timestamp": "0x0",
        "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "extraData": "",
        "gasLimit": "0x8000000",
        "difficulty": "0x4000",
        "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "coinbase": "0x3333333333333333333333333333333333333333",
        "alloc": {}
    }

chainid:        "1"はメインネットを表すので、それ以外を設定
homesteadblock: プライベートチェーンを扱うため、homesteadに切り替えることはないので0に設定
eip155block:    プライベートチェーンを扱うため、ハードフォークするわけではありません。0に設定
eip158block:    プライベートチェーンを扱うため、ハードフォークするわけではありません。0に設定

conibase:       マイニングから収集されたすべての報酬が転送される160bitのアドレス
difficulty:     マイナーが有効なブロックを発見するための難易度
extraData:      バイト文字である必要があるようですが、ここでは空白に設定
gasLimit:       取引を行う際にGasをマイナーに支払いますが、その際の上限値です。
nonce:          ブロックで十分な量の計算が実行されたことを証明する64bitのハッシュ
parentHash:     親ブロックへのポインタ。
mixhash:        ブロックで十分な量の計算が実行されたことを証明する256bitのハッシュ
timestamp:      ブロックが生成された時間。
alloc:          事前に割り当てたれたウォレットのリストを定義できます。
config:         新しく定義されたパラメータです。

$ geth --datadir <DIR> init <DIR>/genesis.json
$ geth --datadir /data init /data/genesis.json

dir:
    <DIR>
    ├── geth
       ├── chaindata
          ├── 000001.log
          ├── CURRENT
          ├── LOCK
          ├── LOG
          └── MANIFEST-000000
       └── lightchaindata
           ├── 000001.log
           ├── CURRENT
           ├── LOCK
           ├── LOG
           └── MANIFEST-000000
    └── keystore


    /eth_private
    ├── genesis.json
    ├── geth
       ├── LOCK
       ├── chaindata
          ├── 000002.ldb
          ├── 000003.log
          ├── CURRENT
          ├── LOCK
          ├── LOG
          └── MANIFEST-000004
       ├── lightchaindata
          ├── 000001.log
          ├── CURRENT
          ├── LOCK
          ├── LOG
          └── MANIFEST-000000
       ├── nodekey
       └── transactions.rlp
    ├── geth.ipc
    └── keystore
         └── UTC--2018-02-19T16-08-13.817911800Z--9c58e4e749db9e43a7608450901cd9687ce2beea

Run:

# with console
$ geth --networkid 1234 --nodiscover --maxpeers 0 --datadir /data console 2>> /data/geth.log

# background
$ nohup geth --networkid 1234 --nodiscover --maxpeers 0 --datadir /data 2>> /data/geth.log &

# background with HTTP-RPC
$ nohup geth --networkid 1234 --nodiscover --maxpeers 0 --datadir /data --rpc 2>> /data/geth.log &

# background
$ nohup geth --networkid 1234 --nodiscover --maxpeers 0 --datadir /data --mine --minerthread 1 --rpc 2>> /data/geth.log &

# Attach
$ geth attach ipc:/data/geth.ipc
$ geth attach rpc:http://localhost:8545

# kill
$ kill <ID>
$ kill -9 <ID>

    --datadir <DIR>
    --networkid "1234"
    --nodiscover
    --mine
    --minerthread 1
    --rpc
    --rpcaddr
    --rpcport
    --rpccorsdomain
    --rpcapi
    --unlock
    --verbosity
    --password

Mist.exe --rpc http://localhost:8545 --swarmurl="http://swarm-gateways.net"

Create User:

> personal.newAccount("password1")
> eth.accounts

$ geth --datadir /data account new
$ geth --datadir /data account list

Mining:

> eth.coinbase

> miner.setEtherbase(eth.accounts[1])

> eth.getBalance(eth.accounts[0])

> eth.getBlock(0)

> miner.start(1)
> miner.stop()

> eth.mining
> eth.blockNumber
> eth.hashrate

> eth.getBalance(eth.coinbase)    # wei
> web3.fromWei(eth.getBalance(eth.coinbase), "ether") # ether (10^18wei)

> eth.getTransaction("<ID>")
> eth.pendingTransactions



tail -f -n 100 geth.log

pm2 start /home/eth-net-intelligence-api/app.json
pm2 stop /home/eth-net-intelligence-api/app.json





DAG: Directed acyclic graph

EOA: externally owned accounts 外部所有アカウント
Contract Account コントラクトアカウント

difficulty(難易度) = difficulty_1_target / current_target

Send:

> personal.unlockAccount(eth.accounts[0], "password1")
> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei("1", "ether")})

> web3.fromWei(eth.getBalance(eth.accounts[1]))


 gasUsed: 21000,
  $> web3.toWei("0.5", "ether") - 21000 * eth.gasPrice


手数料(Ether)=ガス量(Gas × ガス価格(Gwei × 0.000 000 001

1  wei = 0.000 000 000 000 000 001 Ether ※以下18
1 Kwei = 0.000 000 000 000 001 Ether ※以下15
1 Mwei = 0.000 000 000 001 Ether ※以下12
1 Gwei = 0.000 000 001 Ether ※以下9 Gwei = Shannon

Peer:

admin.nodeInfo
{
  enode: "enode://e71be6a047c13e09d3f8e3dba93364cdc0d00c22aba3ab3467b80b334b6c50997db5ef423bd176bd82586c300e7c7f0b353aa1b33352bfbbbc387c3b63214e2f@[::]:50303?discport=0",
  id: "e71be6a047c13e09d3f8e3dba93364cdc0d00c22aba3ab3467b80b334b6c50997db5ef423bd176bd82586c300e7c7f0b353aa1b33352bfbbbc387c3b63214e2f",
  ip: "::",
  listenAddr: "[::]:50303",
  name: "Geth/v1.8.2-unstable-a1984ce7/linux-amd64/go1.9.4",
  ports: {
    discovery: 0,
    listener: 50303
  },
  protocols: {
    eth: {
      config: {
        chainId: 10,
        eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000",
        eip155Block: 0,
        eip158Block: 0,
        homesteadBlock: 0
      },
      difficulty: 32768,
      genesis: "0x9f49d9682abbd44b3621d98a201c8c6061b1b1e59c583321b7ec3e56652caa83",
      head: "0x9f49d9682abbd44b3621d98a201c8c6061b1b1e59c583321b7ec3e56652caa83",
      network: 1234
    }
  }
}

admin.addPeer("enode://e71be6a047c13e09d3f8e3dba93364cdc0d00c22aba3ab3467b80b334b6c50997db5ef423bd176bd82586c300e7c7f0b353aa1b33352bfbbbc387c3b63214e2f@<IP>:<PORT>")

Block:

value:
  number          : [QUANTITY] Serial number
  timestamp       : [QUANTITY] Unix timestamp for when block was collated.
  size            : [QUANTITY] Integer size of this block in bytes.
  difficulty      : [QUANTITY] Integer of difficulty for this block.
  totalDifficulty : [QUANTITY] Integer of total difficulty of chain until this block.
  extraData       : [        ] Extra data field of this block.
  gasLimit        : [QUANTITY] Maximum gas allowed in this block.
  gasUsed         : [QUANTITY] Total used gas by all transactions in this block.
  hash            : [ 32bytes] Hash of this block
  logsBloom       : [256bytes] Bloom filter for logs of block. null when its pending block.
  miner           : [ 20bytes] Address of beneficiary to whom mining rewards were given.
  mixHash         : [ 32bytes]
  nonce           : [  8bytes] Hash of the generated proof-of-work. null when its pending block.
  parentHash      : [ 32bytes] Parent's Hash
  receiptsRoot    : [ 32bytes] Root of receipts trie of block.
  sha3Uncles      : [ 32bytes] SHA3 of uncles data in block.
  stateRoot       : [ 32bytes] Root of final state trie of block.
  transactionsRoot: [ 32bytes] Root of transaction trie of block.
  transactions    : [   ARRAY] Array of transaction objects, or [32bytes] transaction hashes depending on last given parameter.
  uncles          : [   ARRAY] Array of uncle hashes

eth.getBlock(0) {
  number          : 0,
  timestamp       : 0,
  size            : 507,
  difficulty      : 32768,
  totalDifficulty : 32768,
  extraData       : "0x",
  gasLimit        : 251658240,
  gasUsed         : 0,
  hash            : "0x2b180f76a25fe2ff7d9a7158a9c5470525a7b99e130f19d50db9ffe26f53a087",
  logsBloom       : "0x0000........",
  miner           : "0x3333333333333333333333333333333333333333",
  mixHash         : "0x0000000000000000000000000000000000000000000000000000000000000000",
  nonce           : "0x0000000000000042",
  parentHash      : "0x0000000000000000000000000000000000000000000000000000000000000000",
  receiptsRoot    : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles      : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  stateRoot       : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  transactions    : [],
  uncles          : []
}
eth.getBlock(1) {
  number          : 1,
  timestamp       : 1519056700,
  size            : 536,
  difficulty      : 131072,
  totalDifficulty : 163840,
  extraData       : "0xd783010801846765746887676f312e392e34856c696e7578",
  gasLimit        : 251412481,
  gasUsed         : 0,
  hash            : "0x432b7016312ba5b0ea77ac1b7726e3c367ecdbec495c1d7c6b17831f890c62ee",
  logsBloom       : "0x0000........",
  miner           : "0x042bbd1a1181db7b834a01f6f4cdaef79b583c29",
  mixHash         : "0x89d7e6e46dcccf07f36f8a985971f8ff4a56c215b56bcb37dc6ee055136c449e",
  nonce           : "0x1789ae120afe3504",
  parentHash      : "0x2b180f76a25fe2ff7d9a7158a9c5470525a7b99e130f19d50db9ffe26f53a087",
  receiptsRoot    : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles      : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  stateRoot       : "0x778c76b9f9975d2d10f0e2717e5794340ad4c647d11c8717e814e2a1f049abf7",
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  transactions    : [],
  uncles          : []
}

Mining log:
  Block No.1:
  INFO  Commit new mining work                 number=1 txs=0 uncles=0 elapsed=232.3µs
  TRACE Started ethash search for new nonces   miner=0 seed=1696078127198403638
  TRACE Ethash nonce found and reported        miner=0 attempts=374990 nonce=1696078127198778628
  INFO  Successfully sealed new block          number=1 hash=432b700c62ee
  INFO  Mined potential block                  number=1 hash=432b700c62ee
  TRACE Propagated block             hash=432b700c62ee recipients=0 duration=2562047h47m16.854s
  TRACE Announced block              hash=432b700c62ee recipients=0 duration=2562047h47m16.854s

  Block No.2:
  INFO  Commit new mining work                 number=2 txs=0 uncles=0 elapsed=1.029ms
  TRACE Started ethash search for new nonces   miner=0 seed=4662351075533182472
  TRACE Ethash nonce found and reported        miner=0 attempts=110083 nonce=4662351075533292555
  INFO  Successfully sealed new block          number=2 hash=37538dbc107e
  INFO  Mined potential block                  number=2 hash=37538dbc107e
  TRACE Propagated block             hash=37538dbc107e recipients=0 duration=2562047h47m16.854s
  TRACE Announced block              hash=37538dbc107e recipients=0 duration=2562047h47m16.854s

  INFO  Block reached canonical chain          number=1 hash=432b700c62ee
  INFO  Block reached canonical chain          number=2 hash=37538dbc107e