ラベル Etheruem関連 の投稿を表示しています。 すべての投稿を表示
ラベル Etheruem関連 の投稿を表示しています。 すべての投稿を表示

2017年6月27日火曜日

Ethereumで独自ネットワークをたちあげる

Ethereumで独自のブロックチェーンネットワークを構築するための手順を説明する。

  1. 内部ネットワーク用のノード情報などを格納するディレクトリを作成する。

     $ mkdir /home/bushidoyasu/test_e
  2. ジェネシスブロックを定義したファイルを作成する。ファイル名は「myjenesis.json」とする。
    { 
      "config": {
            "chainId": 15,
            "homesteadBlock": 0,
            "eip155Block": 0,
            "eip158Block": 0
        },
     "nonce": "0x00006d6f7264656e",
     "difficulty": "0x200",
     "mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
     "coinbase": "0x0000000000000000000000000000000000000000",
     "timestamp": "0x00",
     "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
     "extraData": "0x",
     "gasLimit": "0x2FEFD8",
     "alloc": {
     }
    }
  3. ブロックチェーン情報を初期化する。

    $  geth --datadir /home/bushidoyasu/test_e init /home/bushidoyasu/test_e/genesis.json
  4. Peerを起動する。

    $ geth --datadir  /home/bushidoyasu/test_e --networkid 15 console
上記で独自ネットワークでPeerが起動した。
あとは、2人分のアカウントを作成して、送金してみる。

■1人目の作成
> personal.newAccount("bushitya")
INFO [06-26|22:39:33] New wallet appeared                      url=keystore:///home/bushidoyasu/te… status=Locked
"0xd550f995919d10ca17c40f0ea217038ee4df7580"

■2人目の作成
> personal.newAccount("masako")
"0xf7d4f230533737e67d4489f789b71dd89b784d93"
> INFO [06-26|22:43:49] New wallet appeared                      url=keystore:///home/bushidoyasu/te… status=Locked

■アカウントの確認
> eth.accounts
["0xd550f995919d10ca17c40f0ea217038ee4df7580", "0xf7d4f230533737e67d4489f789b71dd89b784d93"]

■発掘の開始
※1人目のユーザに報酬が蓄積されていく
> miner.start()

■アカウントのアンロック
※タイムアウト時間は300秒。
> personal.unlockAccount(eth.accounts[0])
Unlock account 0xd550f995919d10ca17c40f0ea217038ee4df7580
Passphrase:
true

■資産の確認
> eth.getBalance(eth.accounts[0])
5000000000000000000
> eth.getBalance(eth.accounts[1])
0

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



2017年6月23日金曜日

Ethereumを動かしてみた

ブロックチェーン基盤の1つであるEtheruemを動かしてみる。

  • Etheruemの実行基盤として、GethとEthの2種類ある。GethはGO言語で記載されている。EthはC++言語で記載されている。今回はGethのほうを動かす。
  • 本番用ネットワークではなく、テスト用のネットワーク(通称:テストネット)につないでみる。
  • 構築環境はUbuntu OSを利用する。

  1. 最初に、必要なパッケージ一式をダウンロードする。

    $ apt-get install software-properties-common
  2. レポジトリにEtheruemを追加する。

    $ add-apt-repository -y ppa:ethereum/ethereum
    $ add-apt-repository -y ppa:ethereum/ethereum-dev
  3. Etheruem資材一式をダウンロードする。

    $ apt-get update
    $ apt-get install ethereum
  4. データディレクトリを作成する。

    $ mkdir /home/bushidoyasu/etheruem_data
  5. テストネットにつないでみる。デーモンではなく、コンソールモードで起動する。

    $  geth --networkid "10" --datadir "/home/bushidoyasu/etheruem_data"   console
    WARN [06-23|21:10:08] No etherbase set and no accounts found as default
    INFO [06-23|21:10:08] Starting peer-to-peer node               instance=Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1
    INFO [06-23|21:10:08] Allocated cache and file handles         database=/home/bushidoyasu/etheruem_data/geth/chaindata cache=128 handles=1024
    INFO [06-23|21:10:08] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Metropolis: 9223372036854775807 Engine: ethash}"
    INFO [06-23|21:10:08] Disk storage enabled for ethash caches   dir=/home/bushidoyasu/etheruem_data/geth/ethash count=3
    INFO [06-23|21:10:08] Disk storage enabled for ethash DAGs     dir=/root/.ethash                               count=2
    INFO [06-23|21:10:08] Initialising Ethereum protocol           versions="[63 62]" network=10
    INFO [06-23|21:10:08] Loaded most recent local header          number=0 hash=d4e567…cb8fa3 td=17179869184
    INFO [06-23|21:10:08] Loaded most recent local full block      number=0 hash=d4e567…cb8fa3 td=17179869184
    INFO [06-23|21:10:08] Loaded most recent local fast block      number=0 hash=d4e567…cb8fa3 td=17179869184
    INFO [06-23|21:10:08] Starting P2P networking
    INFO [06-23|21:10:11] UDP listener up                          self=enode://455d82dddebbb30f51d98cdddd674c4c7ea91a74e226f5a7b51f5dc38bc8b1266e33bd55771633f2f20f74fb1c159b0ca13e51bc5bb53e425231c24cd6836071@[::]:30303
    INFO [06-23|21:10:11] RLPx listener up                         self=enode://455d82dddebbb30f51d98cdddd674c4c7ea91a74e226f5a7b51f5dc38bc8b1266e33bd55771633f2f20f74fb1c159b0ca13e51bc5bb53e425231c24cd6836071@[::]:30303
    INFO [06-23|21:10:11] IPC endpoint opened: /home/bushidoyasu/etheruem_data/geth.ipc
    Welcome to the Geth JavaScript console!

    instance: Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1
    modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0


    >
    上記でノードが立ち上がった。
  6. アカウントの作成してみる。
    > personal.newAccount("bushitya")
    "0x9dff1a413f42870453f2d2bb9c105cdd0108897b"
    INFO [06-23|21:14:19] New wallet appeared                      url=keystore:///home/bushidoyasu/et… status=Locked
    >
    > eth.accounts
    ["0x9dff1a413f42870453f2d2bb9c105cdd0108897b"]
  7. さっそく、発掘してみる。
    > miner.start()
    INFO [06-23|21:15:38] Updated mining threads                   threads=0
    INFO [06-23|21:15:38] Transaction pool price threshold updated price=18000000000
    ・・・
  8. しばらく放置して、自分のアカウントにEtheコインがふえているかを確認する。
    > eth.getBalance("0x9dff1a413f42870453f2d2bb9c105cdd0108897b")
    0

    0コイン。。。テストネットといえど、発掘の道は厳しい。。。。。。