[EOS] Hello World

参考

参考 https://github.com/EOSIO/eos/wiki/Tutorial-Hello-World-Contract

创建实验账户

$ cleos create account eosio hello.code EOS8UCi6r82EvzxKd5KFv3um3fnfaczqZ5aWT6L4zb9ZkHGQUkVkV EOS5Kth7yY94SHU54X7dvpUnthrfnRwgWSDBsdbuYPyEAbczdxRss

编译加载

$ eosiocpp -o hello.wast hello.cpp
$ eosiocpp -g hello.abi hello.cpp
$ cleos set contract hello.code ../hello -p hello.code

打开contract-console开关

修改配置

执行合约

$ cleos push action hello.code hi '["user"]' -p user
executed transaction: 796fbdfc02da6336f18414b67dea0bf4b53816b259fd811ad44f9aabe80a128a  104 bytes  345 us
#    hello.code <= hello.code::hi               {"user":"user"}
>> Hello, user

nodeos日志输出类似如下内容

2721501ms thread-0   producer_plugin.cpp:288       on_incoming_block    ] Received block 9c07ddac78ded760... #533153 @ 2018-06-04T05:45:21.500 signed by producernde1 [trxs: 0, lib: 533152, conf: 0, latency: 1 ms]
2722001ms thread-0   producer_plugin.cpp:288       on_incoming_block    ] Received block 2fd0f4b1dd29155c... #533154 @ 2018-06-04T05:45:22.000 signed by producernde1 [trxs: 0, lib: 533153, conf: 0, latency: 1 ms]
2722045ms thread-0   apply_context.cpp:28          print_debug          ]
[(hello.code,hi)->hello.code]: CONSOLE OUTPUT BEGIN =====================
Hello, user
[(hello.code,hi)->hello.code]: CONSOLE OUTPUT END   =====================
2722501ms thread-0   apply_context.cpp:28          print_debug          ]
[(hello.code,hi)->hello.code]: CONSOLE OUTPUT BEGIN =====================
Hello, user
[(hello.code,hi)->hello.code]: CONSOLE OUTPUT END   =====================
2722501ms thread-0   producer_plugin.cpp:288       on_incoming_block    ] Received block 555c73abc72ea991... #533155 @ 2018-06-04T05:45:22.500 signed by producernde1 [trxs: 1, lib: 533154, conf: 0, latency: 1 ms]
2723001ms thread-0   producer_plugin.cpp:288       on_incoming_block    ] Received block 4c5580392aef0857... #533156 @ 2018-06-04T05:45:23.000 signed by producernde1 [trxs: 0, lib: 533155, conf: 0, latency: 1 ms]

换成tester用户执行,仍可以成功

$ cleos push action hello.code hi '["user"]' -p tester
executed transaction: 3f692d765e15cbd9c2c5754cb740b9de5abee5424c585a1228aea0b7b5ff0a8d  104 bytes  381 us
#    hello.code <= hello.code::hi               {"user":"user"}
>> Hello, user
2760001ms thread-0   producer_plugin.cpp:288       on_incoming_block    ] Received block 5196166ce237ad58... #533230 @ 2018-06-04T05:46:00.000 signed by producernde1 [trxs: 0, lib: 533229, conf: 0, latency: 1 ms]
2760501ms thread-0   producer_plugin.cpp:288       on_incoming_block    ] Received block b6dcd546552d4c59... #533231 @ 2018-06-04T05:46:00.500 signed by producernde1 [trxs: 0, lib: 533230, conf: 0, latency: 1 ms]
2760971ms thread-0   apply_context.cpp:28          print_debug          ]
[(hello.code,hi)->hello.code]: CONSOLE OUTPUT BEGIN =====================
Hello, user
[(hello.code,hi)->hello.code]: CONSOLE OUTPUT END   =====================
2761001ms thread-0   apply_context.cpp:28          print_debug          ]
[(hello.code,hi)->hello.code]: CONSOLE OUTPUT BEGIN =====================
Hello, user
[(hello.code,hi)->hello.code]: CONSOLE OUTPUT END   =====================
2761001ms thread-0   producer_plugin.cpp:288       on_incoming_block    ] Received block 27e2fbef19b849a7... #533232 @ 2018-06-04T05:46:01.000 signed by producernde1 [trxs: 1, lib: 533231, conf: 0, latency: 1 ms]
2761501ms thread-0   producer_plugin.cpp:288       on_incoming_block    ] Received block ecd82015388128fb... #533233 @ 2018-06-04T05:46:01.500 signed by producernde1 [trxs: 0, lib: 533232, conf: 0, latency: 1 ms]

输出两次是因为我有两个节点在运行。

加权限控制

void hi( account_name user ) {
   require_auth( user );
   print( "Hello, ", name{user} );
}

重新编译加载

$ eosiocpp -o hello.wast hello.cpp
$ eosiocpp -g hello.abi hello.cpp
$ cleos set contract hello.code ../hello -p hello.code

重试

$ cleos push action hello.code hi '["tester"]' -p user

你可能感兴趣的:([EOS] Hello World)