「力场」——公链挖矿第一社区
因为吃过EOS版本的亏,所以先看下版本(主网最新版本mainnet-1.2.4,chain_id不是主网ID,因为只是单机版本)。本人系统是Ubunt18.04。
root@kang:/usr/local/eos# cleos get info
{
"server_version": "bbc8ff76",
"chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f",
"head_block_num": 17735,
"last_irreversible_block_num": 17734,
"last_irreversible_block_id": "00004546a6a481051c5969d5c1b2801d63bd245d675178935a26bbd7a426b48c",
"head_block_id": "00004547670c142bd778dd6e297012305874bf33a4e4295e80bb4bc26053e237",
"head_block_time": "2018-09-08T11:44:28.000",
"head_block_producer": "eosio",
"virtual_block_cpu_limit": 200000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 199900,
"block_net_limit": 1048576,
"server_version_string": "mainnet-1.2.4"
}
首先修改下配置,找到
/home/kang/.local/share/eosio/nodeos/config下config.ini文件
contracts-console = false
把上面的`false`改成`true`,保存修改退出。这样我们就可以在终端直接看到智能合约的执行情况,然后重启nodeos(nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin,此次有坑,1.1版本的时候要加钱包插件,当前版本不支持)。
加载基础合约(eosio账户创建并必须导入了公钥私钥)
kangzhiwang@kangzhiwang:/usr/local/eos$ cleos set contract eosio build/contracts/eosio.bios -p eosio@active
Reading WAST/WASM from build/contracts/eosio.bios/eosio.bios.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: 64442ff3defce81330e4be0d030c5d710172feb9ae9cdf7a4d78bd020b8724da 3720 bytes 5223 us
# eosio <= eosio::setcode {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001621260037f7e7f0060057f7e7e7e7e...
# eosio <= eosio::setabi {"account":"eosio","abi":"0e656f73696f3a3a6162692f312e30050c6163636f756e745f6e616d65046e616d650f7065...
2018-09-08T02:33:18.748 thread-0 main.cpp:432 print_result warning: transaction executed locally, but may not be confirmed by the network yet
使用eosiocpp新建合约(eosiocpp环境变量记得配置):
root@kang:/usr/local/eos/contracts# eosiocpp -n hello1
created hello1 from skeleton
进入hell01文件后:
#使用 -o 生成wast文件和wasm文件,
root@kang:/usr/local/eos/contracts/hello1# eosiocpp -o hello1.wast hello1.cpp
#使用 -g 生成abi文件
root@kang:/usr/local/eos/contracts/hello1# eosiocpp -g hello1.abi hello1.cpp
可以看到生成了文件
root@kang:/usr/local/eos/contracts/hello1# ls
hello1.cpp hello1.hpp hello1.wasm hello1.wast
发布合约
cleos set contract eosio /usr/local/eos/contracts/hello1 -p eosio@active
调用合约:kang是调用者用户
root@kang:/usr/local/eos# cleos push action eosio hi '["kang"]' -p kang
executed transaction: b9d2f880f6072f275b9c3c23797b9539c3966c594bce9a7df51ea4d9bc898377 104 bytes 780 us
# eosio <= eosio::hi {"user":"kang"}
>> Hello, kang
×必须完成钱包的创建
×必须完成eosio账户的创建
×必须完成调用者的创建
×config.ini中插件配置(去掉wallet_api_plugin)
plugin = eosio::chain_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::net_plugin
plugin = eosio::net_api_plugin
plugin = eosio::history_plugin
#plugin = eosio::wallet_api_plugin
plugin = eosio::history_api_plugin
plugin = eosio::http_plugin
plugin = eosio::http_client_plugin
参考:
https://mp.weixin.qq.com/s/kWXQGY-ecANNlOZxI4qyLA
https://mp.weixin.qq.com/s/bslylCiKpJUMiFjB9ig2IA
https://mp.weixin.qq.com/s/MqDWoYKe6RkzKQrlXW5MeQ