EOS 学習メモ:Hello World 編

in #eos5 years ago (edited)

dg1uxga7sv.jpg

EOS 学習メモ:検証環境構築編 の続き。

まず、チュートリアルに従って こんな contract を書いておく。

これを前回構築したコンテナの上に持っていく。

 $ docker cp contracts/hello eos:/tmp/contracts 



コンテナに接続。

 $ docker exec -it eos bash



以降、コンテナ上で作業を進める。

まずは hello.cpp をコンパイルして WASM(Web ASseMbly)にする。

 $ cd /tmp/contracts/hello
 $ eosio-cpp -o hello.wasm hello.cpp --abigen



終わったら何ができたか確認してみる。

 $ ls
 hello.abi  hello.cpp  hello.wasm



hello.abihello.wasm ができている。問題なさそう。



contract 用の hello account をつくる。もし wallet がロックされていたら cleos wallet unlock でアンロックしてから実行する。

 $ cleos create account eosio hello EOS74MfAgXfFQX36paLQp5tuApRPoHxn4JCcBiwTFWorF5Cj1qMK7 -p eosio@active
 executed transaction: b624db67435407c4e263e855c968c9ca41ce22e63e7bc4b7dd2eeaaa6d318419  200 bytes  68912 us
 #         eosio <= eosio::newaccount            {"creator":"eosio","name":"hello","owner":{"threshold":1,"keys":[{"key":"EOS74MfAgXfFQX36paLQp5tuApR...



つくった hello account を確認してみる。

 $ cleos get account hello
 created: 2019-01-27T12:09:34.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



問題なさそうなので、contract を hello account に対してデプロイする。

 $ cleos set contract hello . -p hello@active
 Reading WASM from /tmp/contracts/hello/hello.wasm...
 Publishing contract...
 executed transaction: 93ff0b382fe1910a9f3639aecd4df24dfa2e74c596d53f0cbe2a6c5cad99b9c2  1432 bytes  146633 us
 #         eosio <= eosio::setcode               {"account":"hello","vmtype":0,"vmversion":0,"code":"0061736d0100000001390b60027f7e006000017f60027f7f...
 #         eosio <= eosio::setabi                {"account":"hello","abi":"0e656f73696f3a3a6162692f312e31000102686900010475736572046e616d650100000000...



デプロイされたらしい。bobhi action を実行してみる。

 $ cleos push action hello hi '["bob"]' -p bob@active
 executed transaction: 0c13f0292884a7194060b850fb200103c86e115264ab3f452beb3c69b8489f1f  104 bytes  4651 us
 #         hello <= hello::hi                    {"user":"bob"}
 >> Hello, bob



alice でも同じようにやってみる(引数としては "bob" を渡す)。

 $ cleos push action hello hi '["bob"]' -p alice@active
 executed transaction: 9db7965ef754438610685661646be41bbc14d26a3175168c8e0943ebda3a8a22  104 bytes  3617 us
 #         hello <= hello::hi                    {"user":"bob"}
 >> Hello, bob



Hello, bob!

一旦ここまで。

Coin Marketplace

STEEM 0.28
TRX 0.11
JST 0.030
BTC 67536.76
ETH 3771.86
USDT 1.00
SBD 3.57