新手教程 EOS 学习阶段性总结

caokun_8341 · 2018年05月04日 · 最后由 caokun_8341 回复于 2018年05月25日 · 3039 次阅读
本帖已被设为精华帖!

dawn3.0编译过程参考https://github.com/eosio/eos readme.md

# 创建默认钱包
./cleos wallet create

# 设置基础配置智能合约:eosio.bios
./cleos set contract eosio ../../contracts/eosio.bios -p eosio -j

# 设置系统智能合约:eosio.system 部署了该智能合约,eosio账户才可以改包括自己在内的所有账户发行EOS token,才可以执行,注册producer,投票者下注,投票等操作
./cleos set contract eosio ../../contracts/eosio.system -j

# 给eosio账户发行EOS token 10个亿
./cleos push action eosio issue '{"to":"eosio","quantity":"1000000000.0000 EOS"}' --permission eosio@active -j

# 创建两组密钥对
./cleos create key

#keypair1   
#Private key: 5JZ5Wwb8uQbi3A7DmMsD2zevcKCYw1pxmitij1x4xCjU8gv7ucj
#Public key: EOS6a5pr4DS4CksCQSHqTdKMPbAdCyrE4b7QExDwTuCxH1vbkYMqG

#keypair2   
#Private key: 5JKkei9CFtawsvnHt728DUQaahcjHm5nqJsNgZzna9XZKq8eA5c
#Public key: EOS5NiFNF4bG7T49S6f7qVXMAt4RN2WM211s77UZrwD4cz2Xu6gw9

# 导入密钥到默认钱包
./cleos wallet import 5JZ5Wwb8uQbi3A7DmMsD2zevcKCYw1pxmitij1x4xCjU8gv7ucj
./cleos wallet import 5JKkei9CFtawsvnHt728DUQaahcjHm5nqJsNgZzna9XZKq8eA5c

# 查看钱包中的密钥对
./cleos wallet keys

# 创建账户 currency
./cleos create account eosio currency EOS6a5pr4DS4CksCQSHqTdKMPbAdCyrE4b7QExDwTuCxH1vbkYMqG EOS5NiFNF4bG7T49S6f7qVXMAt4RN2WM211s77UZrwD4cz2Xu6gw9 -j

# 设置currency的智能合约
./cleos set contract currency ../../contracts/currency -j

# currency 创建合约token CUR 最大发行量10个亿
./cleos push action currency create '{"issuer":"currency","maximum_supply":"1000000000.0000 CUR","can_freeze":0,"can_recall":0,"can_whitelist":0}' --permission currency@active -j

# 给currency账户发行 10万 CUR
./cleos push action currency issue '{"to":"currency","quantity":"100000.0000 CUR","memo":""}' --permission currency@active -j
# 查询 currency 账户中CUR tokenr的总量
./cleos get currency balance currency currency

# currency token 转账
./cleos push action currency transfer '{"from":"currency","to":"eosio","quantity":"200.0000 CUR","memo":"my first transfer"}' --permission currency@active -j

# 查询余额 CUR
./cleos get currency balance currency eosio
./cleos get currency balance currency currency

# EOS token 转账有问题,转账可以成功,余额查询为空,原来这是EOS的一个BUG,
#eosio 给currency 转账 EOS币后,currency余额查不到,eosio有两个余额
#然后currency 再给eosio转帐0个EOS,再查余额,一切正常。
./cleos transfer eosio currency 100000000 -j

# 查询余额 EOS,eosio账户会有两个余额,currency账户是空的
./cleos get currency balance eosio eosio
./cleos get currency balance eosio currency

查询余额不正确,需要修改chain_plugin.cpp文件 321行开始,get_currency_balance修改成下面这样:把下面-号那一行去掉或注释,添加+号那一行:就是把N(accounts)改成N(account)

vector<asset> read_only::get_currency_balance( const read_only::get_currency_balance_params& p )const {
   vector<asset> results;

   -  walk_table<contracts::key_value_index, contracts::by_scope_primary>(p.code, p.account, N(accounts), [&](const contracts::key_value_object& obj){
  + walk_table<contracts::key_value_index, contracts::by_scope_primary>(p.code, p.account, N(account), [&](const contracts::key_value_object& obj){
       share_type balance;
       fc::datastream<const char *> ds(obj.value.data(), obj.value.size());
       fc::raw::unpack(ds, balance);
       auto cursor = asset(balance, symbol(obj.primary_key));

       if( !p.symbol || cursor.symbol_name().compare(*p.symbol) == 0 ) {
         results.emplace_back(balance, symbol(obj.primary_key));
       }

       // return false if we are looking for one and found it, true otherwise
       return !p.symbol || cursor.symbol_name().compare(*p.symbol) != 0;
     });

   return results;
}
# 下面的命令的注册矿工、押token、投票、使矿工开始工作,并撤销押token,矿工停止工作的命令,只是命令实例
# 可以写脚本生成52个账户,26个投票,另外26个注册成producer
# 然后 投票账户押token
# 最后一对一投票,可实现21个矿工轮流出块。
# 如需笔者提供脚本,可以@我 caokun_8341@sina.com


# 创建三个账户,一个用来投票vo.a,另外两个是矿工 bp.a,bp.b
# 先导入三对私钥,用来创建三个账户,使用默认钱包
# 导入bp.a的私钥
./cleos wallet import 5KXWvLDQnqyDkGwSNhpJc9rWdYdxGHMXSCfyRsaezfWhNxGT8ag
./cleos wallet import 5JaWKNP1uyfxNey6U2T1rJ1GuqakNQCeJ7pmsomL2vf67HQS9nE

# 导入bp.b的私钥
./cleos wallet import 5J8YadJ1Y2HhSRamPMDUNQnSM95BfDiCBiEf1NrAooi9LQAsDUC
./cleos wallet import 5JXUfyVAmMh6sSxNXAdLzk3rDwjyMh8cspWcpD7rPSvHy4c3QFV

# 导入vo.a的私钥
./cleos wallet import 5JPkqi92pc7B6CH2Hftn27BvA6cu1vswUKANLWJ2Fobjg9X3CCq
./cleos wallet import 5JbioArDrpG6EnUp6qtgxHUFTTjBNYiLsr3wzPuCxBzDy7U3B3y

# 创建三个账户 bp.a  bp.b  vo.a
./cleos create account eosio bp.a EOS8dtXWZQWqSv4mk3WPrpMKGywA5pBY1MWxbpSGSLVvV4k98kvxs EOS7fhfs1j5BBQC9bsM5c8c2WZy6NPG6mbAGMuuYJCnKNHfb3vrND
./cleos create account eosio bp.b EOS7PcVKaTP9sLPv8Hff55y3qiLyNtz1vtDtrSdF2DGigmwiMgqCp EOS5nqrTB9Tj4B41AUrHPUf7sfnN1r25b6v6qtYM57n74bpqwXd3e
./cleos create account eosio vo.a EOS6aGsSSs36TytGdwaSb6WN6Jayr5uL5FqqJi97oDSSz7puqNtCu EOS7zKxE4HNRboD2SeZHUcKGbinquBim4FtAqoWJtcQFPQjiZ83bh

# 给三个账户发放EOS token
./cleos push action eosio issue '{"to":"bp.a","quantity":"10000.0000 EOS"}' --permission eosio@active
./cleos push action eosio issue '{"to":"bp.b","quantity":"10000.0000 EOS"}' --permission eosio@active
./cleos push action eosio issue '{"to":"vo.a","quantity":"10000.0000 EOS"}' --permission eosio@active

# bp.a  bp.b 注册矿工 producer_key 需要把对应账户的producer_key active 公钥转换成16进制编码
./cleos push action eosio regproducer  '{"producer":"bp.a","producer_key":"00036e0d69f6d267173ff478815c077bc8f34b24bc687e81f4dec22c4dd6e2fb37b3","prefs":{"base_per_transaction_net_usage":102,"base_per_transaction_cpu_usage":102,"base_per_action_cpu_usage":102,"base_setcode_cpu_usage":102,"per_signature_cpu_usage":102,"per_lock_net_usage":102,"context_free_discount_cpu_usage_num":3,"context_free_discount_cpu_usage_den":102,"max_transaction_cpu_usage":1000002,"max_transaction_net_usage":1000002,"max_block_cpu_usage":10000002,"target_block_cpu_usage_pct":12,"max_block_net_usage":10000002,"target_block_net_usage_pct":12,"max_transaction_lifetime":3602,"max_transaction_exec_time":9902,"max_authority_depth":8,"max_inline_depth":6,"max_inline_action_size":4098,"max_generated_transaction_count":12,"percent_of_max_inflation_rate":52,"storage_reserve_ratio":102}}' --permission {eosio@active,bp.a@active}
./cleos push action eosio regproducer  '{"producer":"bp.b","producer_key":"000276dff979ee0ab622c57577e5ce70041eeae33cdf1d4a00803bebc6dbeaaa5a13","prefs":{"base_per_transaction_net_usage":102,"base_per_transaction_cpu_usage":102,"base_per_action_cpu_usage":102,"base_setcode_cpu_usage":102,"per_signature_cpu_usage":102,"per_lock_net_usage":102,"context_free_discount_cpu_usage_num":3,"context_free_discount_cpu_usage_den":102,"max_transaction_cpu_usage":1000002,"max_transaction_net_usage":1000002,"max_block_cpu_usage":10000002,"target_block_cpu_usage_pct":12,"max_block_net_usage":10000002,"target_block_net_usage_pct":12,"max_transaction_lifetime":3602,"max_transaction_exec_time":9902,"max_authority_depth":8,"max_inline_depth":6,"max_inline_action_size":4098,"max_generated_transaction_count":12,"percent_of_max_inflation_rate":52,"storage_reserve_ratio":102}}' --permission {eosio@active,bp.b@active}

# vo.a 押token
./cleos push action eosio delegatebw '{"from":"vo.a","receiver":"vo.a","stake_net":"100.0000 EOS","stake_cpu":"100.0000 EOS","stake_storage":"0.0000 EOS"}' --permission vo.a@active

# vo.a给 bp.a 投票
./cleos push action eosio voteproducer '{"voter":"vo.a","proxy":"","producers":["bp.a"]}' --permission vo.a@active

# vo.a给 bp.b 投票
./cleos push action eosio voteproducer '{"voter":"vo.a","proxy":"","producers":["bp.b"]}' --permission vo.a@active

# 查vo.a的余额
./cleos get currency balance eos vo.a

#减少押注
./cleos push action eosio undelegatebw '{"from": "vo.a","receiver": "vo.a","unstake_net": "299.0000 EOS","unstake_cpu": "299.0000 EOS","unstake_bytes": 0}' --permission vo.a@active

# 查vo.a的余额
./cleos get currency balance eos vo.a

#减少押注
./cleos push action eosio undelegatebw '{"from": "vo.z","receiver": "vo.z","unstake_net": "1.0000 EOS","unstake_cpu": "1.0000 EOS","unstake_bytes": 0}' --permission vo.z@active

# 取消矿工注册
./cleos push action eosio unregprod '{"producer":"bp.a"}' --permission {eosio@active,bp.a@active}

./cleos push action eosio unregprod '{"producer":"bp.b"}' --permission {eosio@active,bp.b@active}

结论性总结:

  1. 首先需要创建个钱包,才可以做其它操作
  2. 如果要进行EOS token 发行,转账,超级节点注册,投票人押token,投票等操作,部署eosio.bios和eosio.system这两个系统合约是必要前提
  3. procucer 工作前要现创建账户,再注册成为producer,可以脚本实现批量生成密钥和创建账户 4.投票人投票前需要先押token
  4. 使用相关命令使21个producer正常工作
  5. 在prodcuer满21个工作的时候,投票人撤销押token,对应的producer停止工作;在只有一个producer工作的情况下,投票人撤销押token,prodcuer的工作不会停止
  6. 21个producer 工作过程中,按照对应投票人押token的多少,确定打块顺序,一人12打个块,打完就走,等待下轮
  7. 投票人可以随时增加押token,也可以减少押token,减少的部分代币不会立即回到账户
  8. 随着投票人押token多少的变化打块顺序会有相应调整
  9. 如果备选的producers中有某一个支持者(投票人)的押注数量超过目前当选的21个producer中的至少一个prodcuer,被超过的那个当前producer会被超过他的备选producer替换
  10. 总之投票可以是一直在进行的,当前21个producer,随时有可能被替换
  11. 有人说EOS 只有21个超级节点产生区块数据,并非真正的去中心化,其实我觉得:投票不止,替换不息。
共收到 25 条回复
strahe 将本帖设为了精华贴 05月04日 22:25

大佬,能推荐点资料吗,看到你写的真是太棒了!

大神,我试了一下你的命令,但是出现了下面的错误,是什么情况?

cleos push action eosio delegatebw '{"from":"vote","receiver":"vote","stake_net_quantity":"10.0000 EOS","stake_cpu_quantity":"10000.0000 EOS","stake_storage_quantity":"10000.0000 EOS"}' -p vote@active
Error 3030000: transaction validation exception
Ensure that your transaction satisfy the contract's constraint!
Error Details:
condition: assertion failed: unable to find key

请问文中多次用的 -j 是什么意思,后面没有参数吗

OuterST 回复

应该是json输出显示

7楼 已删除

请问 producer_key 是怎么获得的呢?我以为是对应账户的public key 直接转成16进制但是发现不对,所以想请教一下,谢谢!

./cleos push action eosio regproducer  '{"producer":"bp.a","producer_key":"00036e0d69f6d267173ff478815c077bc8f34b24bc687e81f4dec22c4dd6e2fb37b3","prefs":{"base_per_transaction_net_usage":102,"base_per_transaction_cpu_usage":102,"base_per_action_cpu_usage":102,"base_setcode_cpu_usage":102,"per_signature_cpu_usage":102,"per_lock_net_usage":102,"context_free_discount_cpu_usage_num":3,"context_free_discount_cpu_usage_den":102,"max_transaction_cpu_usage":1000002,"max_transaction_net_usage":1000002,"max_block_cpu_usage":10000002,"target_block_cpu_usage_pct":12,"max_block_net_usage":10000002,"target_block_net_usage_pct":12,"max_transaction_lifetime":3602,"max_transaction_exec_time":9902,"max_authority_depth":8,"max_inline_depth":6,"max_inline_action_size":4098,"max_generated_transaction_count":12,"percent_of_max_inflation_rate":52,"storage_reserve_ratio":102}}' --permission {eosio@active,bp.a@active}

@caokun_8341 你好哈,怎么搭建一个局域网测试网络,能不能出个教程,比如如何连接已经出块的节点同步区块以同时出块节点怎么设置,我的出块节点被连接时总是出现Connection reset by peer,不知道怎么修改

想咨询一下: 上面文章里面system合约上链的时候:cleos set contract eosio ../../contracts/eosio.system -j 应该是说这个合约名字叫eosio吧 后来查询余额是 :cleos get currency balance eos eosio 这个意思应该是查询eosio账户在eos智能合约下的余额么? 因为我自己部署了eosio.system后,可以执行转账操作,但是没办法查到余额总是报错

按照楼主全部操作做了一遍,有两个地方有问题:

  1. ./cleos set contract currency ../../contracts/currency -j这个命令,我的eos项目中contracts里没有currency,所以就用eosio.token代替了,不知道对不对
  2. ./cleos get currency balance eos eosio ./cleos get currency balance eos currency 两个命令会报以下错误: Error 3010002: Account Query Exception Most likely, the given account doesn't exist in the blockchain. Error Details: Fail to retrieve account for eos 按照操作修改了代码重新编译后还是出现同样错误,希望楼主帮忙解释一下,非常感谢!
kristieguo 回复

第二个错误我也有。。能转账,但是查询不到有多少EOS 并且我之前用eosio.token生成过EOS币了 不知道会不会有影响。

reluo 回复

你有按照帖子加载currency合约吗?你知道currency合约在哪找到吗?我用dawn 3.0,contracts目录下根本没有currency,eos的git上也没有。

kristieguo 回复

我用的和你一样的eosio.token合约,现在文档和版本都对不上的。

reluo 回复

我已经弄好了,你跟着这个帖子做:https://eosfans.io/topics/435

kristieguo 回复

我看看,谢谢。

你好大佬: 有一个疑问:

#置基础配置智能合约:eosio.bios
./cleos set contract eosio ../../contracts/eosio.bios -p eosio -j

# 设置系统智能合约:eosio.system 部署了该智能合约,eosio账户才可以改包括自己在内的所有账户发行EOS token,才可以执行,注册producer,投票者下注,投票等操作
./cleos set contract eosio ../../contracts/eosio.system -j

这里如果用同一个账户eosio去创建两个合约, 后面一个不会覆盖前面一个么 ?

woshidama 回复

同问。

imoonstal 回复

不会的 昨天尝试了一下 , abi 没变化 还是只有第一个部署上去的合约的abi 。

OuterST 回复

-j 是返回json格式的数据

woshidama 回复

不会覆盖

这个EOS中文社区网站前几天总是上不了

chuanhui 回复

局域网的下周搭建

reluo 回复

不好意思,我一直用currency合约测试,其实部署了eosio.bios和eosio.system这两个合约就可以测试投票

  1. 需要生成密钥,并导入到钱包,才可创建账户,这个不正确。不好意思

到时候 主网 投票 是自动的 还是 人工投票呢 "投票不止 替换不息"

人工投票的话 这么投 有什么回报吗?是不是选出自己想要的 超级节点 ,超级节点 收益会不会回报给投票者,不然投票者怎么会一直去投票

27楼 已删除

@VanJames 投票应该是人工的,会有投票的界面窗口,谁手里有币,想投随时可以投,系统计票和处理轮询替换的机制是实时的,也就是这一轮有你,下一轮不一定有你。投票者先要抵押EOS token,才能投票成功,同时也只有抵押了EOS token,才能作为dapp的开发者在EOS链上发布智能合约,你的智能合约使用多少cpu,net 资源,取决于你抵押的EOS token数量。为了让自己的智能合约运行的良好,开发者肯定希望公链维护者(即block prodcuers或叫超级节点)是自己所信任的机构。所以主要的投票者应该是广大的dapp开发者,而不是简单的持币投机者。投机者只在意币价涨跌,不会在意公链运行状态是否良好,不知道我的理解对不对。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册