EOS初探

本地部署

要求clang llvm 的版本都是4.0 其他版本会构建失败 我的上一篇博文

安装完成 build成功后 启动本地单一链测试环境

此时可以做创建钱包 测试测试

智能合约

源文件

demo.cpp

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.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) )

编译 wast文件

   eosiocpp -o demo.wast demo.cpp

编译完成后,会生成两个新文件,demo.wast, demo.wasm

生成 abi文件

   eosiocpp -g demo.abi demo.cpp

部署智能合约

智能合约是附着在账号上的,需要为合约准备一个账号。

创建钱包 创建key 创建账号

创建key

   $ cleos create key

   Private key: 5Jvwdbn7rBXrBfUnyTJCz3G8oVotE74PBHYVDPm7uVY7UPVA8yi
   Public key: EOS82wU4MF4vv1XnZPgsfGYTW3bm6qDgpmKpszTfVz3dWpeH9mWTN

创建钱包

    $cleos wallet create -n demo

    Creating wallet: demo
    Save password to use in the future to unlock this wallet.
    Without password imported keys will not be retrievable.
    "PW5KVwcyFuTLj4NX7yZu3ShgqdVXmGUS2fpPGFkwXJ8JPSjmBrj3G"

给钱包引入私钥

    $ cleos wallet import  5Jvwdbn7rBXrBfUnyTJCz3G8oVotE74PBHYVDPm7uVY7UPVA8yi -n demo

     imported private key for: EOS82wU4MF4vv1XnZPgsfGYTW3bm6qDgpmKpszTfVz3dWpeH9mWTN

创建账号

     $cleos create account eosio demo.co EOS82wU4MF4vv1XnZPgsfGYTW3bm6qDgpmKpszTfVz3dWpeH9mWTN EOS82wU4MF4vv1XnZPgsfGYTW3bm6qDgpmKpszTfVz3dWpeH9mWTN

      executed transaction: de2bc24f8d2198e76473efb1191b6c14cd3f5f853ce5c2c11460c3c9ca3146f1  200 bytes  201 us
     #         eosio <= eosio::newaccount            {"creator":"eosio","name":"demo.co","owner":{"threshold":1,"keys": 
                                      [{"key":"EOS82wU4MF4vv1XnZPgsfGYTW...
     warning: transaction executed locally, but may not be confirmed by the network yet

绑定合约 到账号

     $cleos set contract demo.co ./demo -p demo.co
      Reading WAST/WASM from ./hello/hello.wasm...
      Using already assembled WASM...
      Publishing contract...
      executed transaction: b26872e44b439ce289f7c449f959a7c9ad574045f69c53039ff365e79e1b8494  1800 bytes  5647 us
     #         eosio <= eosio::setcode               
    {"account":"hello.code","vmtype":0,"vmversion":0,"code":"0061736d01000000013b0c60027f7e006000017e600...
       #         eosio <= eosio::setabi                
    {"account":"hello.code","abi":"00010c6163636f756e745f6e616d650675696e74363401026869000104757365720c6...
    warning: transaction executed locally, but may not be confirmed by the network yet

EOSJS

猜你喜欢

转载自blog.csdn.net/qq_27623521/article/details/80622022
eos