返回介绍

36.5. 编译运行 hello 智能合约

发布于 2023-06-19 14:14:32 字数 2435 浏览 0 评论 0 收藏 0

36.5. 编译运行 hello 智能合约

hello 智能合约是官方提供的一个智能合约例子

找到config.ini中的配置项contracts-console = false 改为 true

		
[root@netkiller ~]# vim ~/.local/share/eosio/nodeos/config/config.ini

# print contract's output to console (eosio::chain_plugin)
contracts-console = true
		
		

源码

		
[root@netkiller hello]# cat /usr/local/src/eos/contracts/hello/hello.cpp 
#include <eosiolib/eosio.hpp>
using namespace eosio;

class hello : public eosio::contract {
  public:
      using contract::contract;

      /// @abi action 
      void hi( account_name user ) {
         print( "Hello, ", name{user} );
      }
};

EOSIO_ABI( hello, (hi) )		
		
		

编译智能合约

		
cd /usr/local/src/eos/build/contracts/hello

[root@netkiller hello]# make 
[  4%] Built target libc++
[  4%] Built target wasm
[  4%] Built target ast
[  4%] Built target asmjs
[  4%] Built target cfg
[ 10%] Built target passes
[ 12%] Built target support
[ 14%] Built target eosio-s2wasm
[ 16%] Built target Platform
[ 16%] Built target Logging
[ 16%] Built target IR
[ 16%] Built target WASM
[ 16%] Built target WAST
[ 16%] Built target eosio-wast2wasm
[ 18%] Built target eosiolib
[ 97%] Built target libc
[100%] Built target hello
		
		
		
[root@netkiller hello]# cleos wallet unlock
password: Unlocked: default

[root@netkiller hello]# cleos set contract contract.hello /usr/local/src/eos/build/contracts/hello -p eosio
Reading WAST/WASM from /usr/local/src/eos/build/contracts/hello/hello.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: f5695465f35b153d65c36cb0e07443fd3d8ccadde9c1daf8c472b0a7e84196b0  4160 bytes  1040 us
#         eosio <= eosio::setcode               "0000000000ea30550000e2170061736d01000000013b0c60027f7e006000017e60027e7e0060027f7f006000017f60027f7...
#         eosio <= eosio::setabi                "0000000000ea3055912b0e656f73696f3a3a6162692f312e30000102686900010475736572046e616d65010000000000008...
warning: transaction executed locally, but may not be confirmed by the network yet
		
		
		
[root@netkiller hello]# cleos push action eosio hi '["neo"]' -p eosio
executed transaction: 476fa2416d227ffe078285714d10d2d726b8e9cc18b9f0ba672bfc1ef93efbd5  104 bytes  284 us
#         eosio <= eosio::hi                    {"user":"neo"}
warning: transaction executed locally, but may not be confirmed by the network yet
		
		

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文