私链eosio.system合约部署


(码不停蹄) #1

eosio.system合约部署

eos版本:v1.0.5

操作系统:centos 7

环境:私有链

目的

由于正式链的ram,net带宽,cpu带宽太宝贵,对于测试的同学建议先在私链上进行测试,避免浪费EOS币。

部署

部署是以私有链并且没有创建任何账号和合约为例,如果已经创建账号和部署智能合约,请对号入座跳着看。


//重复1,2创建必备账号
//eosio.token
//eosio.system
//eosio.ram
//eosio.ramfee
//eosio.stake

//默认在代码根目录下执行
//1.创建密钥对
cleos create key
Private key: 5KKibeZ9KX2bR3MZQnTRVx5aGgpGqtsuitkr21FkpwRERuRk4Ym
Public key: EOS7d1YqzyP52FBkfmyu5pLVPpKjWZ4Ld3DZg8997eFLLZWLb7QUL

//2.创建账号
cleos create account eosio eosio.token ${publicKey} ${publicKey}


//部署eosio.token,发布代币
cleos set contract eosio.token ../../contracts/eosio.token/

cleos push action eosio.token create '["eosio","1000000000.0000 EOS",0,0,0]' -p eosio.token

cleos push action eosio.token issue '["eosio","1000000000.0000 EOS","issue"]' -p eosio

//部署eosio.system,报错如下,要保证开头注明的四个账号已经创建
cleos set contract eosio ../../contracts/eosio.system/ -p eosio
Reading WAST/WASM from ../../contracts/eosio.system/eosio.system.wasm...
Using already assembled WASM...
Publishing contract...
Error 3080006: transaction took too long

//注意
./eosio_build.sh -s "EOS"  购买资源的币种,要使用默认的币种,不写则为SYS

//创建交易账号
cleos system newaccount --stake-net "10.0000 SYS" --stake-cpu "10.0000 SYS" --buy-ram-kbytes 3 eosio eosiotest EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV  EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV 

//查看账号信息,输出资源信息则为部署成功
cleos get account eosiotest
permissions: 
     owner     1:    1 EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
        active     1:    1 EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
memory: 
     quota:     2.973 KiB    used:     2.926 KiB  

net bandwidth: 
     delegated:      10.0000 EOS           (total staked delegated to account from others)
     used:                 0 bytes
     available:        8.145 TiB  
     limit:            8.145 TiB  

cpu bandwidth:
     delegated:      10.0000 EOS           (total staked delegated to account from others)
     used:                 0 us   
     available:        473.5 hr   
     limit:            473.5 hr
     
//给账号转账
cleos push action eosio.token transfer '["eosio","eosiotest","100.0000 SYS",""]' -p eosio

//再将eosiotest转账到eosio,验证资源是否减少
cleos push action eosio.token transfer '["eosiotest","eosio","100.0000 SYS",""]' -p eosio

//再次查看账号信息,发现资源变少
cleos get account eosiotest

问题汇总

Q:部署合约报错:unable to find key

A:4.0以后默认系统币名字是SYS,所以需要发布的代币修改成SYS,或者修改eosio_build.sh脚本中默认名称,重新进行编译(参考下图)
image

Q:transaction took too long

A:nodeos程序启动时添加max-transaction-time或者修改config.ini对应属性,重新启动nodeos

Q:to account does not exist

A:在部署system合约之前,必须创建三个账号eosio.ram,eosio.ramfee,eosio.stake