EOS教程-在EOS上发行自己的代币

in eos •  6 years ago 

在EOS上发行自己的代币

这篇文章主要介绍如何在EOS上面发行自己的代币,下列实验均基于eosio/eos:20180521这个版本的EOS完成。

创建 KEY

这里首先创建一对key:

cleos create key

然后会得到一对key, 这里略去 Private key

Private key: ************************************
Public key: EOS8NFJ49egRRjp4j2kySikZPZ68rWQy5KAR12wygooLPw8ThUqAc

创建钱包

然后我们创建一个钱包,这里暂且将这个钱包叫做token,其中-n用来指定钱包名字

cleos wallet create -n token

得到钱包密码:

***********************************

导入私钥

然后导入我们第一步创建的私钥:

cleos wallet import -n token *******(请将此处替换为第一步中得到的Private key)

创建账户

然后我们可以用第一步得到的public key来创建一个账户noprom:

cleos create account eosio noprom EOS8NFJ49egRRjp4j2kySikZPZ68rWQy5KAR12wygooLPw8ThUqAc EOS8NFJ49egRRjp4j2kySikZPZ68rWQy5KAR12wygooLPw8ThUqAc

得到结果:

executed transaction: 12bb1933cf9363699abebe421bcb22e8b39c86065505f5528c171857a99d1613  200 bytes  364 us
eosio <= eosio::newaccount            {"creator":"eosio","name":"noprom","owner":{"threshold":1,"keys":[{"key":"EOS8NFJ49egRRjp4j2kySikZPZ...

这里的参数的意思是,由eosio这个账户来创建一个叫做noprom的账户,这个账户的公钥为第一步中创建的EOS8NFJ49egRRjp4j2kySikZPZ68rWQy5KAR12wygooLPw8ThUqAc, 这里为了简单我们暂时将2中类型的key都设置为同一个,这两个key分别为owneractive的key。
同理,我们再创建一个叫做小明的账户:

cleos create account eosio xiaoming EOS8NFJ49egRRjp4j2kySikZPZ68rWQy5KAR12wygooLPw8ThUqAc EOS8NFJ49egRRjp4j2kySikZPZ68rWQy5KAR12wygooLPw8ThUqAc

得到结果:

executed transaction: 5fba9946ddb63e3a438875ada8be009771ff2b8b08140db36b4f1f2155fe46f2  200 bytes  350 us
eosio <= eosio::newaccount            {"creator":"eosio","name":"xiaoming","owner":{"threshold":1,"keys":[{"key":"EOS8NFJ49egRRjp4j2kySikZ...

部署代币合约

首先创建一个专门部署这个合约的账号:

cleos create account eosio eosio.token EOS69CVnKwKMbNfGpdjfYMdLrvUwUenHDbSw9pFQHT9iaFUTWSA8Q EOS69CVnKwKMbNfGpdjfYMdLrvUwUenHDbSw9pFQHT9iaFUTWSA8Q

然后我们部署eosio.token这个合约:

cleos set contract eosio.token /opt/eosio/bin/data-dir/contracts/eosio.token -p eosio.token

这样合约就部署完了。

发行代币

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

得到结果:

executed transaction: 31508996812b5d6369c099e30047fab919b294baba12eae434f755a6aef2327a  120 bytes  423 us
eosio.token <= eosio.token::create          {"issuer":"eosio","maximum_supply":"1000000000.0000 EOSDEVS"}

这里我们执行了eosio.token这个合约里面的create方法,这个方法的作用就是创建一个代币。
这里我们创建了一个叫做EOSDEVS的代币,发行者为eosio这个账户,发行总量为1000000000.0000,使用eosio.token这个用户来创建这个代币。

给用户发币

接着我们可以给刚才创建的用户发放我们刚才创建的EOSDEVS代币:

cleos push action eosio.token issue '[ "noprom", "10.0000 EOSDEVS", "created by eosdevs" ]' -p eosio

操作结果:

executed transaction: 82059a49ada36b1124359314b6a139eba2e4b917da8240aec1f8a0ac378249c9  136 bytes  1162 us
eosio.token <= eosio.token::issue           {"to":"noprom","quantity":"10.0000 EOSDEVS","memo":"created by eosdevs"}
eosio.token <= eosio.token::transfer        {"from":"eosio","to":"noprom","quantity":"10.0000 EOSDEVS","memo":"created by eosdevs"}
eosio <= eosio.token::transfer        {"from":"eosio","to":"noprom","quantity":"10.0000 EOSDEVS","memo":"created by eosdevs"}
noprom <= eosio.token::transfer        {"from":"eosio","to":"noprom","quantity":"10.0000 EOSDEVS","memo":"created by eosdevs"}

这样就给noprom这个账户发了10个EOSDEVS代币,并加了一个备注: created by eosdevs

获取账户余额

我们可以通过下面的方法来获得用户的账户余额:

cleos get currency balance eosio.token noprom

可以得到:

10.0000 EOSDEVS

其中eosio.token为我们部署的合约,noprom为账户名。

转账

要转账,我们可以调用eosio.token这个合约里面的transfer方法:

cleos push action eosio.token transfer '[ "noprom", "xiaoming", "5.0000 EOSDEVS", "Transfer from noprom to xiaoming" ]' -p noprom

操作结果:

executed transaction: 46d84306ee989d3c75235b2271ab9baed336b3fe403473357cbad3cf4094c756  160 bytes  937 us
eosio.token <= eosio.token::transfer        {"from":"noprom","to":"xiaoming","quantity":"5.0000 EOSDEVS","memo":"Transfer from noprom to xiaomin...
noprom <= eosio.token::transfer        {"from":"noprom","to":"xiaoming","quantity":"5.0000 EOSDEVS","memo":"Transfer from noprom to xiaomin...
xiaoming <= eosio.token::transfer        {"from":"noprom","to":"xiaoming","quantity":"5.0000 EOSDEVS","memo":"Transfer from noprom to xiaomin...

这里我们从noprom这个账户向xiaoming这个账户转了5个EOSDEVS 代币,备注为Transfer from noprom to xiaoming
然后我们可以查看nopromxiaoming的账户余额:

cleos get currency balance eosio.token noprom
5.0000 EOSDEVS
cleos get currency balance eosio.token xiaoming

可以看到转账成功,nopromxiaoming 都有5个EOSDEVS 代币。

Github

这篇文章也在Github上可以找到: 在EOS上发行自己的代币

关于我们

本文由中国领先的EOS竞选节点 @EOSpace 编写。
我们将会发布更多教程,如果您想了解更多关于EOS开发相关技术的信息,请加入我们的电报小组:EOSpace

我们的产品

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @noprom! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!