Smart Contract - Hello World
阿新 • • 發佈:2018-11-22
【編寫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 [email protected]
8、使用 push action 命令來使用
-p 指明本身的許可權
leos push action hello hi '["bob"]' -p [email protected]
參考:
1、https://developers.eos.io/eosio-home/docs/your-first-contract