概述
1. 文章摘要
【本文目标】
在EOS私链环境发行TOKEN代币,并进行转账交易。
【环境前置条件】
1)已搭建好EOS私链环境(可参考第4课 如何在UBUNTU虚拟机上编译EOS完成环境搭建?)
2)会进行相关钱包账号的操作( 参考第5课 EOS环境搭建入门(私链节点-钱包-密钥-账号))
3) 本文操作时已存在以下资源信息
1] 钱包名称 duncanwang,对应的解锁密码为"PW5JYSZRvSropLhguyxYY1zXgeQidSZnRKPKUXr2JUVTYay2zhuxT"
2] 系统私钥/公钥对已导入钱包:
EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV / 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
【技术收获】
1) 创建自有代币
2) 发行自有代币
3) 代币转账操作
2. 操作内容
本文的操作内容的流程图如下所示:
2.1 创建账户
创建3个账号,eosio.token账号用于创建ColorBayToken代币,wangdenghui账号用于发行代币,创建账户ouyanggege用于接收代币。
创建eosio.token账号
cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
输出内容:
duncanwang@duncanwang:~$ cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 -n duncanwang
imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
duncanwang@duncanwang:~$ cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
executed transaction: 5679e2ad487fe7956ab287beb1c8642635e493d54ef4e948be06e0c24af48520
200 bytes
1133 us
#
eosio <= eosio::newaccount
{"creator":"eosio","name":"eosio.token","owner":{"threshold":1,"keys":[{"key":"EOS6MRyAjQq8ud7hVNYcf...
warning: transaction executed locally, but may not be confirmed by the network yet
创建wangdenghui账号
cleos create account eosio wangdenghui EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
输出内容:
duncanwang@duncanwang:~/eos$ cleos create account eosio wangdenghui EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
executed transaction: 09688423e0f287cd0ae829fc358b58ecd0ec7f6e7e403684969bcaa3c7227a91
200 bytes
320 us
#
eosio <= eosio::newaccount
{"creator":"eosio","name":"wangdenghui","owner":{"threshold":1,"keys":[{"key":"EOS6MRyAjQq8ud7hVNYcf...
warning: transaction executed locally, but may not be confirmed by the network yet
创建ouyanggege账号
cleos create account eosio ouyanggege EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
输出内容:
duncanwang@duncanwang:~/eos$ cleos create account eosio ouyanggege EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
executed transaction: 316a20b2c20669d853b116d6126b9f09fdece00a62c888acc2d4ab4c845d875b
200 bytes
738 us
#
eosio <= eosio::newaccount
{"creator":"eosio","name":"ouyanggege","owner":{"threshold":1,"keys":[{"key":"EOS6MRyAjQq8ud7hVNYcfn...
warning: transaction executed locally, but may not be confirmed by the network yet
2.2 部署代币合约
cleos set contract eosio.token build/contracts/eosio.token -p eosio.token
参数说明:
-p,–permission TEXT 表示授权账号,该合约授权给eosio.token账号。
代币合约eosio.token能让许多不同的代币同时在一个智能合约上发行,但是却能被不同用户管理。
duncanwang@duncanwang:~/eos$ cleos set contract eosio.token build/contracts/eosio.token -p eosio.token
Reading WAST/WASM from build/contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: 74e746a1bcb58d69a47b8182a960f2657b56023ab30df959ff5e29405fec785b
8104 bytes
2088 us
#
eosio <= eosio::setcode
{"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7e...
#
eosio <= eosio::setabi
{"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d65...
warning: transaction executed locally, but may not be confirmed by the network yet
2.3 创建一个代币
cleos push action eosio.token create ‘[ “eosio”, “1000000000.0000 CBT”, 0, 0, 0]’ -p eosio.token
参数说明:
1) create 函数是用来新建一种代币,并输入代币的各种属性,同时 create 函数也是一个 action。action 是 eos 智能合约的接口函数,定义外界可以对智能合约做什么动作。
结合操作命令,说明各个参数的定义:
create( account_name issuer,/发行方账号的名称为"eosio"/
asset maximum_supply,/总供应量为10亿和代币名称CBT (ColorBayToken的缩写)/
uint8_t can_freeze,/资产是否可以冻结,0表示否/
uint8_t can_recall,/资产是否可以召回,0表示否/
uint8_t can_whitelist );/资产是否可以设置白名单,0表示无/
2)-p,–permission Type: Text - 授权给账号eosio.token
duncanwang@duncanwang:~/eos$ cleos push action eosio.token create '[ "eosio", "1000000000.0000 CBT", 0, 0, 0]' -p eosio.token
executed transaction: 791687224acb86a715639af9b3b4660ac06ac07908c8746851382be661218739
120 bytes
4703 us
#
eosio.token <= eosio.token::create
{"issuer":"eosio","maximum_supply":"1000000000.0000 CBT"}
warning: transaction executed locally, but may not be confirmed by the network yet
2.4 发行代币
cleos push action eosio.token issue ‘[ “wangdenghui”, “10000.0000 CBT”, “first ColorBayToken issue” ]’ -p eosio
参数说明:
1) issue 函数是用来增发代币,eosio.token 合约并不是新建了代币就会得到代币,新建的代币只是存储了资料,发币者要想获取代币,需要调用 issue action 来获得代币。
void issue(
account_name to, /代币的发行方为账户为wangdenghui,之前已经创建/
asset quantity, /发行代币的数量为10000个,代币名称为CBT/
string memo ); /表示备注说明,不能超过256个字节/
执行输入结果如下:
duncanwang@duncanwang:~/eos$ cleos push action eosio.token issue '[ "wangdenghui", "10000.0000 CBT", "first ColorBayToken issue" ]' -p eosio
executed transaction: 33b23322d6a413108350a21f23c77150d77de71a8aeeaefd5befd9e30ceec288
144 bytes
2602 us
#
eosio.token <= eosio.token::issue
{"to":"wangdenghui","quantity":"10000.0000 CBT","memo":"first ColorBayToken issue"}
#
eosio.token <= eosio.token::transfer
{"from":"eosio","to":"wangdenghui","quantity":"10000.0000 CBT","memo":"first ColorBayToken issue"}
#
eosio <= eosio.token::transfer
{"from":"eosio","to":"wangdenghui","quantity":"10000.0000 CBT","memo":"first ColorBayToken issue"}
#
wangdenghui <= eosio.token::transfer
{"from":"eosio","to":"wangdenghui","quantity":"10000.0000 CBT","memo":"first ColorBayToken issue"}
warning: transaction executed locally, but may not be confirmed by the network yet
##2.5 代币转账
辉哥账号转账给欧阳哥哥合计8000个彩贝币,用于支付午餐费用。
cleos push action eosio.token transfer ‘[ “wangdenghui”, “ouyanggege”, “8000.0000 CBT”, “pay for lunch!” ]’ -p wangdenghui
转账成功输出结果:
duncanwang@duncanwang:~/eos$ cleos push action eosio.token transfer '[ "wangdenghui", "ouyanggege", "8000.0000 CBT", "pay for lunch!" ]' -p wangdenghui
executed transaction: 42c0f99566561977424df6417581114c3d9865c5194256f6b7a1311abf97802a
144 bytes
2011 us
#
eosio.token <= eosio.token::transfer
{"from":"wangdenghui","to":"ouyanggege","quantity":"8000.0000 CBT","memo":"pay for lunch!"}
#
wangdenghui <= eosio.token::transfer
{"from":"wangdenghui","to":"ouyanggege","quantity":"8000.0000 CBT","memo":"pay for lunch!"}
#
ouyanggege <= eosio.token::transfer
{"from":"wangdenghui","to":"ouyanggege","quantity":"8000.0000 CBT","memo":"pay for lunch!"}
warning: transaction executed locally, but may not be confirmed by the network yet
2.6 查询余额
查询辉哥和欧阳哥哥的账号,核实金额是否已到账。
cleos get currency balance eosio.token wangdenghui
cleos get currency balance eosio.token ouyanggege
正确输出结果:
duncanwang@duncanwang:~/eos$ cleos get currency balance eosio.token wangdenghui
2000.0000 CBT
duncanwang@duncanwang:~/eos$ cleos get currency balance eosio.token ouyanggege
8000.0000 CBT
2.7 阅读eosio.token智能合约代码
EOS 官方提供了一个代币(资产)智能合约 Demo —— eosio.token,这个示例合约给出了 EOS 官方智能合约开发的标准结构和开发方法,并且真正的 EOS 代币也会借鉴这个示例合约的逻辑,是 EOS 智能合约入门的经典案例。
默认情况下,该智能合约存在路径:~/eos/contracts/eosio.token
文件解释如下:
eosio.token.hpp - 头文件,定义类和函数
eosio.token.cpp - 实现
eosio.token.abi - Application Binary Interface,是一个接口文件,描述了智能合约与上层应用之间的数据交换格式
CMakeLists.txt - 编译文件
3. 参考
1) 在EOSIO上发行代币
2) Introduction to the EOSIO Token Contract
3)【许晓笛】EOS智能合约案例解析(1)
最后
以上就是激昂月饼为你收集整理的第7课 技术小白如何在EOS上发行通证(TOKEN)?1. 文章摘要2. 操作内容3. 参考的全部内容,希望文章能够帮你解决第7课 技术小白如何在EOS上发行通证(TOKEN)?1. 文章摘要2. 操作内容3. 参考所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复