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

2017年6月19日月曜日

GO言語で始めるEthereumプログラミング(Gethを使ったアカウント管理編)

環境


OS : osx

目的

Gethの"Basic Use Case Documentation"にある3つをそれぞれ試す。
Ethereum開発に必要なClientであるGethの使い方を学ぶ。


始めに

  • アカウントを暗号化する際のパスワードを忘れるとそのアカウントにはアクセスできなくなるので注意
  • gethはaccountというサブコマンドによってアカウント管理できる
  • 鍵は<DATADIR>/keystore以下に保存される
    • 定期的なバックアップをオススメする
    • 鍵のバックアップに関する詳細:Backup & restore
  • ヘルプコマンド
    • geth account help <subcommand>


アカウント管理でできること

  • 新たなアカウントの作成
  • 既存アカウントのリスト化
  • 新たなアカウントに対する秘密鍵のインポート
  • 最新の鍵形式への移行とパスワード変更

アカウントの作成

新たなアカウントを作る

前回の投稿で作成したgo-ethereum内で作業を行う。
$ geth account new
WARN [06-18|10:42:55] 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: {2e9f6ce30074338fac346090d4bc6a1fd5506f38}

リスト化した情報を参照してみる。


$ geth account list
Account #0: {2e9f6ce30074338fac346090d4bc6a1fd5506f38} keystore:///Users/xxx/Library/Ethereum/keystore/UTC--2017-06-18T13-53-47.688998272Z--2e9f6ce30074338fac346090d4bc6a1fd5506f38

アカウント情報を暗号化形式で保存する。この時に指定するパスフレーズはアカウントをアンロックする時に必要なので決して忘れてはならない。
$ > personal.newAccount test

上記の作業前後でディレクトリ内には以下のような変化が。
(前)
$ ls
AUTHORS  build  core  les  rlp
COPYING  circle.yml crypto  light  rpc
COPYING.LESSER cmd  eth  log  swarm
Dockerfile common  ethclient metrics  tests
Makefile compression ethdb  miner  trie
README.md consensus ethstats mobile  vendor
VERSION  console  event  node  whisper
accounts containers interfaces.go p2p
appveyor.yml contracts internal params

(後)


$ ls
AUTHORS   console   metrics
COPYING   containers  miner
COPYING.LESSER  contracts  mobile
Dockerfile  core   node
Makefile  crypto   p2p
README.md  eth   params
VERSION   ethclient  personal.newAccount
accounts  ethdb   rlp
appveyor.yml  ethstats  rpc
build   event   swarm
circle.yml  interfaces.go  tests
cmd   internal  trie
common   les   vendor
compression  light   whisper
consensus  log
アカウントに関するファイルが生成されている。

秘密鍵のインポートによってアカウントを作る

暗号化されてない秘密鍵を使用する場合。これは不要なのでスキップする。

既存のアカウントをアップデートする

アカウントを暗号化形式で最新バージョンに保存する。
この時アカウントのロックを解除するためにパスフレーズを求められる。
$ geth account update 2e9f6ce30074338fac346090d4bc6a1fd5506f38
Unlocking account 2e9f6ce30074338fac346090d4bc6a1fd5506f38 | Attempt 1/3
Passphrase: 
INFO [06-19|22:07:53] Unlocked account                         address=0x2e9f6ce30074338fac346090d4bc6a1fd5506f38
Please give a new password. Do not forget this password.
Passphrase: 
Repeat passphrase: 

プリセールウォレットをインポートする

スキップ。

アカウントのリスト化と残高のチェック

現在のアカウントのリスト化

$ geth account list
Account #0: {2e9f6ce30074338fac346090d4bc6a1fd5506f38} keystore:///Users/kichino/Library/Ethereum/keystore/UTC--2017-06-18T13-53-47.688998272Z--2e9f6ce30074338fac346090d4bc6a1fd5506f38

2017年6月18日日曜日

GO言語で始めるEthereumプログラミング(ビルド編)

環境


OS : osx


インストール

以下入力コマンド。出力内容は最後のみ表示。

$ brew tap ethereum/ethereum

$ brew install ethereum

$ cd Desktop
$ mkdir ethe
$ cd ethe
$ git clone https://github.com/ethereum/go-ethereum

$ brew install go

$ cd go-ethereum

$ make geth
build/env.sh go run build/ci.go install ./cmd/geth
>>> /usr/local/Cellar/go/1.8.1/libexec/bin/go install -ldflags -X main.gitCommit=431cf2a1e453346bcc627ac1fb9df3950a6c3499 -s -v ./cmd/geth
github.com/ethereum/go-ethereum/common/hexutil
github.com/ethereum/go-ethereum/common/math
github.com/ethereum/go-ethereum/rlp
github.com/ethereum/go-ethereum/crypto/sha3
github.com/ethereum/go-ethereum/crypto/secp256k1
github.com/ethereum/go-ethereum/common
github.com/ethereum/go-ethereum/vendor/github.com/go-stack/stack
github.com/ethereum/go-ethereum/log
github.com/ethereum/go-ethereum/params
github.com/ethereum/go-ethereum/vendor/github.com/rcrowley/go-metrics
github.com/ethereum/go-ethereum/vendor/gopkg.in/karalabe/cookiejar.v2/collections/prque
github.com/ethereum/go-ethereum/vendor/github.com/aristanetworks/goarista/monotime
github.com/ethereum/go-ethereum/common/mclock
github.com/ethereum/go-ethereum/event
github.com/ethereum/go-ethereum/crypto/randentropy
github.com/ethereum/go-ethereum/vendor/github.com/pborman/uuid
github.com/ethereum/go-ethereum/vendor/github.com/rjeczalik/notify
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/pbkdf2
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/scrypt
github.com/ethereum/go-ethereum/cmd/internal/browser
github.com/ethereum/go-ethereum/vendor/github.com/edsrzf/mmap-go
github.com/ethereum/go-ethereum/common/bitutil
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/util
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/cache
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/comparer
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/storage
github.com/ethereum/go-ethereum/trie
github.com/ethereum/go-ethereum/vendor/github.com/rcrowley/go-metrics/exp
github.com/ethereum/go-ethereum/metrics
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/errors
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/filter
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/iterator
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/journal
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/opt
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/memdb
github.com/ethereum/go-ethereum/vendor/github.com/golang/snappy
github.com/ethereum/go-ethereum/vendor/github.com/hashicorp/golang-lru/simplelru
github.com/ethereum/go-ethereum/vendor/github.com/hashicorp/golang-lru
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb/table
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/context
github.com/ethereum/go-ethereum/vendor/github.com/rs/xhandler
github.com/ethereum/go-ethereum/vendor/github.com/rs/cors
github.com/ethereum/go-ethereum/vendor/github.com/syndtr/goleveldb/leveldb
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/websocket
github.com/ethereum/go-ethereum/vendor/gopkg.in/fatih/set.v0
github.com/ethereum/go-ethereum/rpc
github.com/ethereum/go-ethereum/vendor/golang.org/x/crypto/ripemd160
github.com/ethereum/go-ethereum/ethdb
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/httpu
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/scpd
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/soap
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/ssdp
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html/atom
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/internal/identifier
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/transform
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/internal
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/charmap
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/japanese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/korean
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/simplifiedchinese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/traditionalchinese
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/internal/utf8internal
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/runes
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/internal/tag
github.com/ethereum/go-ethereum/vendor/github.com/jackpal/go-nat-pmp
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/language
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/unicode
github.com/ethereum/go-ethereum/p2p/netutil
github.com/ethereum/go-ethereum/vendor/gopkg.in/sourcemap.v1/base64vlq
github.com/ethereum/go-ethereum/vendor/gopkg.in/sourcemap.v1
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/token
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/dbg
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/file
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/ast
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/registry
github.com/ethereum/go-ethereum/vendor/github.com/karalabe/hid
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto/parser
github.com/ethereum/go-ethereum/vendor/golang.org/x/text/encoding/htmlindex
github.com/ethereum/go-ethereum/vendor/golang.org/x/net/html/charset
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp
github.com/ethereum/go-ethereum/vendor/github.com/robertkrimen/otto
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/dcps/internetgateway1
github.com/ethereum/go-ethereum/vendor/github.com/huin/goupnp/dcps/internetgateway2
github.com/ethereum/go-ethereum/p2p/nat
github.com/ethereum/go-ethereum/log/term
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-colorable
github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1
github.com/ethereum/go-ethereum/les/flowcontrol
github.com/ethereum/go-ethereum/internal/jsre/deps
github.com/ethereum/go-ethereum/internal/debug
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-isatty
github.com/ethereum/go-ethereum/vendor/github.com/fatih/color
github.com/ethereum/go-ethereum/internal/web3ext
github.com/ethereum/go-ethereum/vendor/github.com/peterh/liner
github.com/ethereum/go-ethereum/vendor/golang.org/x/tools/go/ast/astutil
github.com/ethereum/go-ethereum/vendor/golang.org/x/tools/imports
github.com/ethereum/go-ethereum/vendor/github.com/maruel/panicparse/stack
github.com/ethereum/go-ethereum/vendor/github.com/mattn/go-runewidth
github.com/ethereum/go-ethereum/vendor/github.com/mitchellh/go-wordwrap
github.com/ethereum/go-ethereum/vendor/github.com/nsf/termbox-go
github.com/ethereum/go-ethereum/vendor/github.com/naoina/go-stringutil
github.com/ethereum/go-ethereum/vendor/github.com/gizak/termui
github.com/ethereum/go-ethereum/vendor/github.com/naoina/toml/ast
github.com/ethereum/go-ethereum/vendor/github.com/naoina/toml
github.com/ethereum/go-ethereum/internal/jsre
github.com/ethereum/go-ethereum/console
github.com/ethereum/go-ethereum/crypto
github.com/ethereum/go-ethereum/crypto/ecies
github.com/ethereum/go-ethereum/core/types
github.com/ethereum/go-ethereum/p2p/discover
github.com/ethereum/go-ethereum/p2p/discv5
github.com/ethereum/go-ethereum/accounts/abi
github.com/ethereum/go-ethereum
github.com/ethereum/go-ethereum/core/state
github.com/ethereum/go-ethereum/accounts
github.com/ethereum/go-ethereum/core/vm
github.com/ethereum/go-ethereum/accounts/keystore
github.com/ethereum/go-ethereum/consensus
github.com/ethereum/go-ethereum/consensus/misc
github.com/ethereum/go-ethereum/consensus/clique
github.com/ethereum/go-ethereum/consensus/ethash
github.com/ethereum/go-ethereum/eth/downloader
github.com/ethereum/go-ethereum/eth/fetcher
github.com/ethereum/go-ethereum/p2p
github.com/ethereum/go-ethereum/core
github.com/ethereum/go-ethereum/accounts/usbwallet
github.com/ethereum/go-ethereum/accounts/abi/bind
github.com/ethereum/go-ethereum/ethclient
github.com/ethereum/go-ethereum/node
github.com/ethereum/go-ethereum/whisper/whisperv5
github.com/ethereum/go-ethereum/eth/filters
github.com/ethereum/go-ethereum/internal/ethapi
github.com/ethereum/go-ethereum/miner
github.com/ethereum/go-ethereum/light
github.com/ethereum/go-ethereum/eth/gasprice
github.com/ethereum/go-ethereum/eth
github.com/ethereum/go-ethereum/les
github.com/ethereum/go-ethereum/ethstats
github.com/ethereum/go-ethereum/contracts/release
github.com/ethereum/go-ethereum/cmd/utils
github.com/ethereum/go-ethereum/cmd/geth
Done building.
Run "build/bin/geth" to launch geth.