美文网首页从零开始学EOS应用开发
【EOSIO】创建账户(account)并发行自己的代币

【EOSIO】创建账户(account)并发行自己的代币

作者: 面壁者Z | 来源:发表于2018-08-29 12:23 被阅读55次

    在创建账户之前,由于每个账户(account)都需要两个权限:owner和active,所以要导入至少两组密钥对。

    1,生成密钥对

    使用cleos的create key来生成密钥对

    cleos create key --to-console # 生成owner私钥对
    cleos create key --to-console # 生成active私钥对

    请记录下生成的这两组密钥对。

    2,将两组密钥导入钱包中

    使用cleos的wallet import来导入

    cleos wallet open # 打开默认钱包default
    cleos wallet unlock # 解锁默认钱包default
    password: #键入或复制钱包密码
    cleos wallet import # 导入密钥对1
    private key: # 键入或复制第一组密钥对的私钥
    cleos wallet import # 导入密钥对2
    private key: # 键入或复制第二组密钥对的私钥
    cleos wallet keys # 可以看看当前存在的密钥对

    3,创建currency账户

    使用cleos的create account来创建用户,由目前唯一的账户eosio来授权

    cleos create account eosio currency <public OwnerKey> <public ActiveKey>

    这样会返回一组json数据,并且提示那你暂时没有被confirm。

    4, 查询账户

    创建完账户后,我们需要看一看是否成功,这时候可以用到cleos的get account命令:

    cleos get account currency

    我们可以看到返回了权限组,owner是我们上面的第一组公钥,active是第二组的公钥,然后后面现实了内存(memory)、网络、cpu等信息。

    5,部署代币发行合约

    eos自带了一个代币发行合约,位于 ~/eos/build/contracts/eosio.token
    和部署eosio.bios合约方法一样

    cleos wallet open
    cleos wallet unlock
    password: ***
    cleos wallet list #看一下default后面是否有个号,表示解锁状态
    cleos set contract currency eosio.token

    返回正常的json字符串表示部署成功。

    6,使用currency的active权限发行一个代币

    假设我们发行的代币为BTC,发行了为100万个

    cleos push action currency create '{"issuer":"currency", "maximum_supply":"1000000.0000 BTC", "can_freeze":"0","can_recall":"0","can_whitelist":"0"}' --permission currency@active

    如果返回一串json数据,表示成功。

    现在,我们向currency账户发送100个BTC:

    cleos push action currency '{"to":"currency","quantity":"1000.0000 BTC","memo":""}' --permission currency@active

    然后查看一下余额:

    cleos get table currency currency accounts

    可以看到返回的balance为1000 BTC

    7,试着通过currency账户向eosio转账100 BTC

    cleos push action currency transfer '{"from":"currency","to":"eosio","quantity":"100.0000 BTC ","memo":"hello world"}' --permission currency@active
    cleos get table currency eosio accounts # 看eosio账户余额:100BTC
    cleos get table currency currenncy accounts # 看currency账户余额900BTC

    好了,发币,转账,一气呵成!
    我是王越,一个eosio开发小白,欢迎加我微信361757(暗号eos),一起加入EOSIO开发俱乐部群!

    相关文章

      网友评论

        本文标题:【EOSIO】创建账户(account)并发行自己的代币

        本文链接:https://www.haomeiwen.com/subject/rzfhwftx.html