2018年 9月 1日の投稿一覧

Ethereum – スマートコントラクト作成 – プライベート・ネットワークの作成

https://book.ethereum-jp.net/first_use/connect_to_private_net.html

Ubuntuが良さそうですが、手元にCentos6しかなかったのでとりあえすやってみます。

Ethereumでは以下の3つの形態のP2Pネットワークを構築しブロックチェーンを運用していくことが可能です。

パブリック・ネットワーク:不特定多数のノードのノードが参加し、かつその参加に制限が全くないネットワークです。参加ノードはそのネットワーク上で共有管理されたブロックチェーンに対して自由に、読み取り、トランザクションの発行、マイニングが可能です。仮想通貨としてのEthereumや、多くのパブリックなdAppはこのパブリックネットワーク上で運用されています。
コンソーシアム・ネットワーク:あらかじめ参加を許されたノードのみが参加することが可能なネットワークです。参加を許されるノードは一つの組織のみに管理されたものとは限らず、複数の利害関係が一致しない組織がそれぞれのノードを管理することが通常です。例えば国際送金の管理を行うブロックチェーンを構築したい場合、予め参加を許された複数の金融企業がそれぞれ管理するノードをこのP2Pのネットワークに参加することで、一つの企業にのみ管理されたシステムではない半非中央集権なシステムが構築可能になります。
プライベート・ネットワーク:一つの組織のみに管理されたノードのみが参加することが可能なネットワークです。ネットワークは自身の管理下に置くことが可能になり、中央集権的なP2Pシステムが可能になります。


mkdir eth_private_net

vi eth_private_netg/enesis.json


{
  "config": {
    "chainId": 15
  },
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "",
  "gasLimit": "0x8000000",
  "difficulty": "0x4000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}


 geth --datadir ~/eth_private_net init ~/eth_private_net/genesis.json
INFO [02-15|04:00:34] Maximum peer count                       ETH=25 LES=0 total=25
INFO [02-15|04:00:34] Allocated cache and file handles         database=/home/dp/eth_private_net/geth/c
haindata cache=16 handles=16
INFO [02-15|04:00:34] Writing custom genesis block 
INFO [02-15|04:00:34] Persisted trie from memory database      nodes=0 size=0.00B time=6.642µs gcnodes=0 gcsize
=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [02-15|04:00:34] Successfully wrote genesis state         database=chaindata                              
         hash=7b2e8b…7e0432
INFO [02-15|04:00:34] Allocated cache and file handles         database=/home/dp/eth_private_net/geth/l
ightchaindata cache=16 handles=16
INFO [02-15|04:00:34] Writing custom genesis block 
INFO [02-15|04:00:34] Persisted trie from memory database      nodes=0 size=0.00B time=2.335µs gcnodes=0 gcsize
=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [02-15|04:00:34] Successfully wrote genesis state         database=lightchaindata                         
              hash=7b2e8b…7e0432


geth --networkid "15" --nodiscover --datadir ~/eth_private_net/  console 2>> ~/eth_privat
e_net/err.log
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.1-unstable-dc7ca52b/linux-amd64/go1.9.2
 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
>

Genesisブロックの確認


> eth.getBlock(0)
{
  difficulty: 16384,
  extraData: "0x",
  gasLimit: 134217728,
  gasUsed: 0,
  hash: "0x7b2e8be699df0d329cc74a99271ff7720e2875cd2c4dd0b419ec60d1fe7e0432",
  logsBloom: "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000",
  miner: "0x3333333333333333333333333333333333333333",
  mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  nonce: "0x0000000000000042",
  number: 0,
  parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 507,
  stateRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  timestamp: 0,
  totalDifficulty: 16384,
  transactions: [],
  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  uncles: []
}
> 

Ethereum – スマートコントラクト開発 – 開発環境を構築する

Go Ehtereumのインストール


brew tap ethereum/ethereum
ずらずら
==> Tapping ethereum/ethereum
Cloning into '/usr/local/Homebrew/Library/Taps/ethereum/homebrew-ethereum'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
Tapped 3 formulae (32 files, 33.7KB)


brew install ethereum


npm install -g ethereumjs-testrpc


mba:~ dp$ ll
.e
.eclipse/                     .electrum-ltc/                .esets/
.electron/                    .emulator_console_auth_token  .ethereum_dev/
mba:~ dp$  geth --datadir .ethereum_dev/privatenet init .ethereum_dev/privatenet/genesis.json 
INFO [02-15|11:53:46] Maximum peer count                       ETH=25 LES=0 total=25
INFO [02-15|11:53:46] Allocated cache and file handles         database=/Users/dp/.ethereum_dev/privatenet/geth/chaindata cache=16 handles=16
INFO [02-15|11:53:46] Writing custom genesis block 
INFO [02-15|11:53:46] Persisted trie from memory database      nodes=0 size=0.00B time=19.224µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [02-15|11:53:46] Successfully wrote genesis state         database=chaindata                                           hash=17fa94…cca181
INFO [02-15|11:53:46] Allocated cache and file handles         database=/Users/dp/.ethereum_dev/privatenet/geth/lightchaindata cache=16 handles=16
INFO [02-15|11:53:46] Writing custom genesis block 
INFO [02-15|11:53:46] Persisted trie from memory database      nodes=0 size=0.00B time=4.766µs  gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [02-15|11:53:46] Successfully wrote genesis state         database=lightchaindata                                           hash=17fa94…cca181