executed transaction: 0d6af1d2734c5410fd46a1018723996bbad3d9e5361f5e57bb32b4959794534d 200 bytes 3106 us # eosio <= eosio::newaccount {"creator":"eosio","name":"hello.code","owner":{"threshold":1,"keys":[{"key":"EOS5wbpduFSWAMGEgPiCay... warning: transaction executed locally, but may not be confirmed by the network yet ]
7 编写EOS智能合约
1 2 3
mkdir hello cd hello vim hello.cpp
hello.cpp源代码
1 2 3 4 5 6 7 8
#include "hello.hpp" using namespace eosio;
ACTION hello::hi( name user ) { print_f( "Hello % from hello", user ); }
EOSIO_DISPATCH( hello, (hi) )
hello.hpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <eosiolib/eosio.hpp>
using namespace eosio;
CONTRACT hello : public eosio::contract { public: using contract::contract;
ACTION hi( name user );
// accessor for external contracts to easily send inline actions to your contract using hi_action = action_wrapper<"hi"_n, &hello::hi>; };
cleos set contract hello.code ../hello -p hello.code@active
部署成功
1 2 3 4 5 6
Reading WASM from /wwwroot/block_chain/contracts/hello/hello.wasm... Publishing contract... executed transaction: 511b47b0ede6b4b0a00c5ca44b972c1e17c7d091b05ea0be1bfd4228d96fd645 1392 bytes 6870 us # eosio <= eosio::setcode {"account":"hello.code","vmtype":0,"vmversion":0,"code":"0061736d0100000001300960017f006000017f60027... # eosio <= eosio::setabi {"account":"hello.code","abi":"0e656f73696f3a3a6162692f312e310001026869000001000000000000806b0268690... warning: transaction executed locally, but may not be confirmed by the network yet ]
11 调用合约
1
cleos push action hello.code hi '["user"]' -p hello.code@active
12 加入对输出hello的权限认证
1 2 3 4
ACTION hello::hi( name user ) { require_auth( user ); print_f( "Hello % from hello", user ); }