EOS:入门踩坑之学习 发行token(通证) 4

0.跟随EOS教程https://developers.eos.io/eosio-home/docs/token-contract及大佬们
初步了解合约之后,是时候发行自己的token(代币)。
首先我们需要官方提供的token源合约。
1.下载官方提供的合约

[root@bogon token]# git clone https://github.com/EOSIO/eosio.contracts --branch v1.4.0 --single-branch

[root@bogon token]# cd eosio.contracts/

在这里插入图片描述
其他不重要,进入eosio.token

2.为合约创建个账户
要先解锁钱包 cleos wallet unlock

[root@bogon eosio.token]# cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

在这里插入图片描述

3.编译合约
官方编译(esio.cdt Contract Development Toolkit, )采用:
直接生成x.wasm x.abi

eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp --abigen

这里并没有采用官方的编译方式,使用js4eos:
将eosio.token.hpp拷贝到src/中

[root@bogon eosio.token]# cp include/eosio.token/eosio.token.hpp src/

然后编译:

[root@bogon src]# js4eos compile2 -o eosio.token.wasm eosio.token.cpp   

在这里插入图片描述
error1 :
eosio.token.cpp:6:10: fatal error: ‘eosio.token/eosio.token.hpp’ file not found #include <eosio.token/eosio.token.hpp>

查看源文件eosio.token.cpp:

vim eosio.token.cpp

在这里插入图片描述

在这里插入图片描述
可以看到 本地的头文件是 eosio.token.hpp,源文件为<<eosio.token/eosio.token.hpp>>其寻找范围为系统库目录。所以修改eosio.token.cpp修改头文件"eosio.token.hpp"将寻找路径改为现在的目录。

然后再次编译:

[root@bogon src]# js4eos compile2 -o eosio.token.wasm eosio.token.cpp  

在这里插入图片描述

b.生成.abi

[root@bogon src]# js4eos compile2 -g eosio.token.abi eosio.token.cpp  --contract xxx

–contract xxxxx… 类名

4.部署合约

合约名要和生成的xx.wasm xx.abi,同名否则会提示找不到

在这里插入图片描述
Error 3160009: No wast file found
将目录改为和生成的wasm同名文件。
先将目录拷贝一份:

[root@bogon eosio.token]# cp  src src2

在这里插入图片描述
cp: 略过目录"src"

[root@bogon eosio.token]# cp -r src src2
cp --help

-r, --recursive 递归复制目录及其子目录内的所有内容

成功。
改名:

[root@bogon eosio.token]# mv src eosio.token

再次部署:

[root@bogon eosio.token]# cleos set contract eosio.token eosio.token --abi eosio.token.abi -p eosio.token@active -x 1000

在这里插入图片描述

5.创造token(通证)
终于要发行。。。。哈哈哈

To create a new token call the create(…) action with the proper arguments. This action accepts 1 argument, it’s a symbol_name type composed of two pieces of data, a maximum supply float and a symbol_name in capitalized alpha characters only, for example “1.0000 SYM”. The issuer will be the one with authority to call issue and or perform other actions such as freezing, recalling, and whitelisting of owners,

创造一个新的token,push一个create 动作,这个动作接受一个_name类型参数。由两部分组成,一个最大发行量,一个大写字母_name,如 “1.0000SYS”,发行人将是有权发行或执行其他行动,如冻结,召回,白名单的所有者。

cleos push action eosio.token create '[ "eosio", "1000000000.0000 NB"]' -p eosio.token@active

在这里插入图片描述
这里我们发行了这么多1000000000.0000 NB,是不是感觉要发。。。。
Error 3040006: Transaction Expiration Too Far
将 -x 1000减少到10,这里的-x : the expiration time of your transaction(Expiration time of transaction )交易过期时间

6.发送通证
我们向xiaoming发送10000.0000的NB

[root@bogon eosio.token]# cleos push action eosio.token2 issue '["xiaoming","10000.0000 NB","memo"]' -p eosio@active -x 1

这步还要减少Expiration time of transaction,这里-p eosio

在这里插入图片描述

交易信息:
executed transaction: ec0a3eac5df92d6dd261150cac88b42e2e5bfe989ebd2fa3b5daa449280630ec  128 bytes  896 us
#  eosio.token2 <= eosio.token2::issue          {"to":"xiaoming","quantity":"10000.0000 NB","memo":"memo"}
#  eosio.token2 <= eosio.token2::transfer       {"from":"eosio","to":"xiaoming","quantity":"10000.0000 NB","memo":"memo"}
#         eosio <= eosio.token2::transfer       {"from":"eosio","to":"xiaoming","quantity":"10000.0000 NB","memo":"memo"}
#      xiaoming <= eosio.token2::transfer       {"from":"eosio","to":"xiaoming","quantity":"10000.0000 NB","memo":"memo"}

This time the output contains several different actions: one issue and three transfers. While the only action signed was issue, the issue action performed an “inline transfer” and the “inline transfer” notified the sender and receiver accounts. The output indicates all of the action handlers that were called, the order they were called in, and whether or not any output was generated by the action.
这一次,输出包含几个不同的动作:一个发送和三个转移。虽然签署的唯一操作是签发,但签发操作执行“内联转移”,而“内联转移”通知发送方和接收方帐户。输出指示所有被调用的动作处理程序、它们被调用的顺序,以及动作是否生成任何输出。
This time the output contains several different actions: one issue and three transfers. While the only action signed was issue, the issue action performed an “inline transfer” and the “inline transfer” notified the sender and receiver accounts. The output indicates all of the action handlers that were called, the order they were called in, and whether or not any output was generated by the action.
从技术上讲,eosio.token合同可以跳过内联转移,而选择直接修改余额。然而,在这种情况下,eosio.token合同遵循我们的令牌约定,该约定要求所有账户余额都可由引用它们的转移操作的总和导出。它还要求通知资金的发送方和接收方,以便它们能够自动处理存款和提款。
To inspect the transaction, try using the -d -j options, they indicate “don’t broadcast” and “return transaction as json,” which you may find useful during development.
查看交易,请尝试使用-d-j选项,它们表示不要广播”和以json格式返回。

[root@bogon eosio.token]# cleos push action eosio.token issue '["bob", "100.0000 NB", "memo"]' -p eosio@active -d -j

在这里插入图片描述

7.转移通证

xiaoming已经有了一些代币,转移1000.0000到bob。

[root@bogon eosio.token]# cleos push action eosio.token transfer '["xiaoming","bob","1000.0000 NB","money"]' -p xiaoming@active

在这里插入图片描述

8.查看一下bob和xiaoming的账户

[root@bogon eosio.token]# cleos get currency balance eosio.token bob NB
[root@bogon eosio.token]# cleos get currency balance eosio.token xiaoming NB

输出:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值