Smart Contract - Hello World

编写Smart Contract

1、包含头文件.

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>

2、使用命名空间

using namespace eosio;

3、实现一个空的合约

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

4、合约中添加一个action

class hello : public contract {
  public:
      using contract::contract;
  
      [[eosio::action]]
      void hi( name user ) {
         print( "Hello, ", name{user});
      }
};

 5、添加转发表

EOSIO_DISPATCH( hello, (hi))

6、使用 eosio-cpp -o --abigen 生成 .wasm、.abi

eosio-cpp -o hello.wasm hello.cpp --abigen

7、用set contract 命令发布合约 

  

  -p 指明需要 hello的 active权限

cleos set contract hello /home/ubuntu/contracts/hello -p hello@active

8、使用 push action 命令来使用

  

-p 指明本身的权限

leos push action hello hi '["bob"]' -p bob@active

参考:

1、https://developers.eos.io/eosio-home/docs/your-first-contract

猜你喜欢

转载自www.cnblogs.com/tekkaman/p/9998699.html