EOS 部署、调用合约

合约代码

 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract/hello  cat hello.cpp
#include 

using namespace eosio;

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

      [[eosio::action]]
      void hii( name user ) {
         print( "Hello, ", user);
      }
};                                                                                                                                                     wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract/hello 

编译代码生成.abi.wasm

 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract/hello  eosio-cpp hello.cpp -o hello.wasm
Warning, empty ricardian clause file
Warning, empty ricardian clause file
Warning, action  does not have a ricardian contract
 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract/hello  ll
total 24
-rw-r--r--  1 wujinquan  staff   572B  9  9 17:39 hello.abi
-rw-r--r--  1 wujinquan  staff   247B  9  9 16:25 hello.cpp
-rwxr-xr-x  1 wujinquan  staff   813B  9  9 17:39 hello.wasm
 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract/hello 

部署合约

 ✘ wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract/hello  cd ../
 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract  cleos set contract wujinquan hello  //表示账户wujinquan部署hello合约
Reading WASM from /Users/wujinquan/workspace/eos/contract/hello/hello.wasm...
Publishing contract...
executed transaction: ad200ef280058c0bac4a81ca64742cf7c93f5ec84623c356827790c57fb45c92  696 bytes  229 us
#         eosio <= eosio::setcode               {"account":"wujinquan","vmtype":0,"vmversion":0,"code":"0061736d0100000001370b6000017f60027f7f006003...
#         eosio <= eosio::setabi                {"account":"wujinquan","abi":"0e656f73696f3a3a6162692f312e3100010368696900010475736572046e616d650100...
warning: transaction executed locally, but may not be confirmed by the network yet         ]
 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract 

调用合约

 ✘ wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract  cleos push action wujinquan hii '["helloworld"]' -p hello.eos  //表示调用者为`hello.eos` 调用合约部署者`wujinquan`部署的合约中的`hii`方法
executed transaction: df4e1b1e3423e9b68f6c2a4fbea1b644aef75d94e87570248a82cf9561a9c6ad  104 bytes  186 us
#     wujinquan <= wujinquan::hii               {"user":"helloworld"}
>> Hello, helloworld
warning: transaction executed locally, but may not be confirmed by the network yet         ]
 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eos/contract 

根据txid查看调用合约的详情

{"id":"df4e1b1e3423e9b68f6c2a4fbea1b644aef75d94e87570248a82cf9561a9c6ad","block_num_hint":155185}

{
    "id": "df4e1b1e3423e9b68f6c2a4fbea1b644aef75d94e87570248a82cf9561a9c6ad",
    "trx": {
        "receipt": {
            "status": "executed",
            "cpu_usage_us": 186,
            "net_usage_words": 13,
            "trx": [
                1,
                {
                    "signatures": [
                        "SIG_K1_KeKL6K3uRLuFG7a3qsGgJULY75pLirNCQSGrjtQnQTUP5mg4cZVj5abdEs1mMxGmzGiESUiyDt3kymYnw7bfPvCTG85FtA"
                    ],
                    "compression": "none",
                    "packed_context_free_data": "",
                    "packed_trx": "f521765d2f5e176fb935000000000100009846dbe99ee60000000000009c6b010000c054011aa36a00000000a8ed32320800408a97721aa36a00"
                }
            ]
        },
        "trx": {
            "expiration": "2019-09-09T09:57:09",
            "ref_block_num": 24111,
            "ref_block_prefix": 901345047,
            "max_net_usage_words": 0,
            "max_cpu_usage_ms": 0,
            "delay_sec": 0,
            "context_free_actions": [],
            "actions": [
                {
                    "account": "wujinquan",
                    "name": "hii",
                    "authorization": [
                        {
                            "actor": "hello.eos",
                            "permission": "active"
                        }
                    ],
                    "data": {
                        "user": "helloworld"
                    },
                    "hex_data": "00408a97721aa36a"
                }
            ],
            "transaction_extensions": [],
            "signatures": [
                "SIG_K1_KeKL6K3uRLuFG7a3qsGgJULY75pLirNCQSGrjtQnQTUP5mg4cZVj5abdEs1mMxGmzGiESUiyDt3kymYnw7bfPvCTG85FtA"
            ],
            "context_free_data": []
        }
    },
    "block_time": "2019-09-09T09:56:39.500",
    "block_num": 155185,
    "last_irreversible_block": 155303,
    "traces": []
}

你可能感兴趣的:(EOS)