動機はさておき、とりあえず チュートリアル 通りに進めてみる。
まずは Docker で検証用のコンテナをよしなに起動して接続する。今回は Ubuntu 18.04 で。
$ docker run -id --name eos ubuntu:18.04
$ docker exec -it eos bash
以下、コンテナ上での作業。まずは諸々のインストール。
$ apt update
$ apt install curl jq wget -y
$ cd /tmp
$ wget https://github.com/eosio/eos/releases/download/v1.5.0/eosio_1.5.0-1-ubuntu-18.04_amd64.deb
$ apt install ./eosio_1.5.0-1-ubuntu-18.04_amd64.deb -y
$ mkdir contracts
keosd を起動する。
keosd (key + eos = keosd) - component that securely stores EOSIO keys in wallets.
$ keosd &
nodeos も起動する。
nodeos (node + eos = nodeos) - the core EOSIO node daemon that can be configured with plugins to run a node. Example uses are block production, dedicated API endpoints, and local development.
$ nodeos -e -p eosio \
--plugin eosio::producer_plugin \
--plugin eosio::chain_api_plugin \
--plugin eosio::http_plugin \
--plugin eosio::history_plugin \
--plugin eosio::history_api_plugin \
--data-dir /tmp/contracts/eosio/data \
--config-dir /tmp/contracts/eosio/config \
--access-control-allow-origin='*' \
--contracts-console \
--http-validate-host=false \
--verbose-http-errors \
--filter-on='*' >> nodeos.log 2>&1 &
./nodeos.log を覗いてブロックが生成されていることを確認。
ウォレットを確認してみる。
$ cleos wallet list
Wallets:
[]
ない。まだつくってないから当然ではある。
API を叩いてみる。
$ curl -s http://localhost:8888/v1/chain/get_info | jq
{
"server_version": "ea08cfd3",
"chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f",
"head_block_num": 588,
"last_irreversible_block_num": 587,
"last_irreversible_block_id": "0000024b582c1a8ea65f952291b8225bb7298da51c643cdb2e6fb0551c50214d",
"head_block_id": "0000024c7c802352433e3ae9db9805d3bebc31b7cf1f89538588c26d246affea",
"head_block_time": "2019-01-21T10:18:57.000",
"head_block_producer": "eosio",
"virtual_block_cpu_limit": 359422,
"virtual_block_net_limit": 1886117,
"block_cpu_limit": 199900,
"block_net_limit": 1048576,
"server_version_string": "v1.5.0"
}
それっぽい情報が返ってくる。特に問題なさそう。
CDT をインストールする。
The EOSIO Contract Development Toolkit, CDT for short, is a collection of tools related to contract compilation. Subsequent tutorials use the CDT primarily for compiling contracts and generating ABIs.
$ wget https://github.com/EOSIO/eosio.cdt/releases/download/v1.4.1/eosio.cdt-1.4.1.x86_64.deb
$ apt install ./eosio.cdt-1.4.1.x86_64.deb
ウォレットをつくる。
$ cleos wallet create --to-console
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"..."
最後の "..." にパスワードが表示されるので、メモしておく。また、production 環境でやるときはシェルの履歴に残さないように気をつけてねとのこと。
If using cleos in production, it's wise to instead use
--to-fileso your wallet password is not in your bash history.
ウォレットはデフォルトで閉じてるらしいので、開く。
$ cleos wallet open
Opened: default
ウォレットを確認してみる。
$ cleos wallet list
Wallets:
[
"default"
]
特に問題なさそうなので、ウォレットをアンロックする。アンロックするには、さっきメモしたパスワードが必要。
$ cleos wallet unlock
もう一度ウォレットを確認する。
$ cleos wallet list
Wallets:
[
"default *"
]
* がついてればアンロックされているということらしい。
秘密鍵を生成する。
$ cleos wallet create_key
Created new private key with a public key of: "EOS74MfAgXfFQX36paLQp5tuApRPoHxn4JCcBiwTFWorF5Cj1qMK7"
表示された公開鍵はメモしておく。
development key をインポートする。
そもそも EOS チェーンには、eosio というデフォルトのシステムユーザーがいるらしく、この account がチェーンのセットアップなどを行うらしい。で、eosio に対応した development key というものがあるらしく、eosio としてトランザクションに署名したりするためにこれをインポートしておく。ということらしいので、ドキュメントに記載されている秘密鍵 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 をそのままインポートする。
Every new EOSIO chain has a default "system" user called "eosio". This account is used to setup the chain by loading system contracts that dictate the governance and consensus of the EOSIO chain. Every new EOSIO chain comes with a development key, and this key is the same. Load this key to sign transactions on behalf of the system user (eosio)
$ cleos wallet import
当然、この秘密鍵はみんなにバレてるので、production 環境で使っちゃダメ。
先ほどメモした公開鍵と紐付けて、検証用の account alice と bob をつくる。
$ cleos create account eosio alice EOS74MfAgXfFQX36paLQp5tuApRPoHxn4JCcBiwTFWorF5Cj1qMK7
executed transaction: 021a0af84219fc43a3f8cd66c52d2d54cd00c24e6a9a09986b054b342e04225d 200 bytes 26565 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"alice","owner":{"threshold":1,"keys":[{"key":"EOS74MfAgXfFQX36paLQp5tuApR...
$ cleos create account eosio bob EOS74MfAgXfFQX36paLQp5tuApRPoHxn4JCcBiwTFWorF5Cj1qMK7
executed transaction: b35bbceea7fe9aee90ea55b92585730ce34f4571a1e9a158b6f591ab053d93a9 200 bytes 511 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"bob","owner":{"threshold":1,"keys":[{"key":"EOS74MfAgXfFQX36paLQp5tuApRPo...
account name はあくまで ownership の識別子でしかないとのこと。公開鍵は変更することができるらしいが、公開鍵を変更しても account の ownership は変更されないらしい。この辺はまだちょっとよくわからないので、後ほど理解を深める。
Be aware that the account name is the only identifier for ownership. You can change the public key but it would not change the ownership of your EOSIO account.
alice の情報を確認する。
$ cleos get account alice
created: 2019-01-21T11:16:39.500
permissions:
owner 1: 1 EOS74MfAgXfFQX36paLQp5tuApRPoHxn4JCcBiwTFWorF5Cj1qMK7
active 1: 1 EOS74MfAgXfFQX36paLQp5tuApRPoHxn4JCcBiwTFWorF5Cj1qMK7
memory:
quota: unlimited used: 2.66 KiB
net bandwidth:
used: unlimited
available: unlimited
limit: unlimited
cpu bandwidth:
used: unlimited
available: unlimited
limit: unlimited
alice には owner と active という 2 つの公開鍵が紐づいている。セキュリティ面を加味して、owner は cold しておいて active を常用するのが基本らしい。こうしておくことで、active の情報が漏れてしまった場合にも owner で制御権を取り戻せるとのこと。
Notice that actually
alicehas bothownerandactivepublic keys. EOSIO has a unique authorization structure that has added security for you account. You can minimize the exposure of your account by keeping the owner key cold, while using the key associated with youractivepermission. This way, if youractivekey were ever compromised, you could regain control over your account with yourownerkey.
また、チュートリアルなので owner と active に同じ鍵を使っているが、セキュリティ的にはよろしくないので、production 環境では別々にしてねとのこと。
とりあえず今日はここまで。