本文我们将弄清楚什么是EOS代币以及如何自己创建和部署EOS代币。

与以太坊相反,EOS带有即插即用的代币智能合约。以太坊拥有ERC20智能合约,EOS拥有eosio.token智能合约。Eosio.token智能合约允许你通过提供最大代币供应数量和代币的书面定义,通过向帐户发放代币以及在帐户之间转移代币来创建你自己的代币。EOS区块链上的EOS代币使用相同的智能合约签发。

cleos --url https://api.main.alohaeos.com:443 get currency stats eosio.token EOS
{
"EOS": {
"supply": "1003605574.9616 EOS",
"max_supply": "10000000000.0000 EOS",
"issuer": "eosio"
}
}

url参数指定你连接的哪一个节点。你可以在官方网站上查看更多提供API的节点。

安装Cleos

Cleos是一个命令行工具,它与nodeos公开的REST API进行交互。我们需要cleos来运行所有命令来与EOS区块链进行交互。你可以使用Docker,AWS Image或编译源代码来安装cleos。安装的最终结果必须在你的终端中是可用的。

cleos
ERROR: RequiredError: Subcommand required
Command Line Interface to EOSIO Client
Usage: cleos [OPTIONS] SUBCOMMAND Options:
-h,--help Print this help message and exit
-u,--url TEXT=http://localhost:8888/
the http/https URL where nodeos is running
--wallet-url TEXT=http://localhost:8900/
the http/https URL where keosd is running
-r,--header pass specific HTTP header; repeat this option to pass multiple headers
-n,--no-verify don't verify peer certificate when using HTTPS
-v,--verbose output verbose actions on error
--print-request print HTTP request to STDERR
--print-response print HTTP response to STDERR
Subcommands:
version Retrieve version information
create Create various items, on and off the blockchain
get Retrieve various items and information from the blockchain
set Set or update blockchain state
transfer Transfer EOS from account to account
net Interact with local p2p network connections
wallet Interact with local wallet
sign Sign a transaction
push Push arbitrary transactions to the blockchain
multisig Multisig contract commands
system Send eosio.system contract action to the blockchain.

创建钱包

钱包是存储可能与一个或多个帐户的权限相关联密钥的客户端。理想情况下,钱包具有受高熵密码保护的锁定(加密)和解锁(解密)状态。EOSIO/eos存储库捆绑了一个名为cleos的命令行界面客户端,它与一个名为keosd的lite客户端连接在一起,它们展示了这种模式。

让我们创建一个名为“treasure”的东西。

cleos wallet create --name treasure
Creating wallet: treasure
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5J2DTM7kpPaihUH35pLTJrvhjgZ11SY4FqxYbo6geWvEH4SNvMC"

你必须将密码保存在安全的地方,因为如果它丢失了,则无法恢复钱包内的所有密钥。

现在我们需要为所有者和活动权限生成两对密钥。之后,我们将它们导入我们的钱包。

cleos create key #owner
Private key: 5HsrZsLeUoDvBCFT2JSvgg3KrfwE7BXAJkUBSwnTwX27Cgabumj
Public key: EOS8VMwRNWWHwov4vyzJiq9uTEyzcny8QKXv7CJxGQAwjSTncyv51 cleos create key #active
Private key: 5JtrJNbJPfzm8XPMddANGYT9yzaqo8gwTEpmSrgQNhtoPXL9Ynd
Public key: EOS8CCRKHAbhBim6LimdvhhzhEYiKNnLRhuMD1Zqx5Cut52moBRmH cleos wallet import 5HsrZsLeUoDvBCFT2JSvgg3KrfwE7BXAJkUBSwnTwX27Cgabumj --name treasure #owner
imported private key for: EOS8VMwRNWWHwov4vyzJiq9uTEyzcny8QKXv7CJxGQAwjSTncyv51 cleos wallet import 5JtrJNbJPfzm8XPMddANGYT9yzaqo8gwTEpmSrgQNhtoPXL9Ynd --name treasure #owner
imported private key for: EOS8CCRKHAbhBim6LimdvhhzhEYiKNnLRhuMD1Zqx5Cut52moBRmH

创建帐号

要在EOS区块链中执行任何操作,你需要拥有一个帐户。

帐户是存储在区块链中的我们可以看明白的名称。它可以由一个人或一些人拥有,具体取决于权限配置。需要一个帐户来将交易转移或推送到区块链。

帐户本质上是一些公共或私有密钥,是一个唯一的名称。密钥存放在钱包中。帐户存储在EOS区块链中。

在本地创建帐户很容易,你只需运行cleos create account命令,因为你拥有默认的eosio帐户,这在Mainnet上显然不是这样。要在Mainnet上创建帐户,你需要已经拥有它的人的帮助,例如zeoseos-account-creator,这需要花钱。此外,你只能创建12个符号的帐户,并且仅包含a-z小写,1-5个数字。在我看来,这是非常严格的限制。要获得名称较短的帐户,你必须进行竞价。考虑到(双关的语意)你可以转售EOS帐户,抢注量是非常巨大的。考虑到所有这些,我们将使用Testnet来节省金钱和时间。

EOS Jungle Tesnet在尽可能模拟主网。转到jungle.cryptolions.io并点击Create Account链接。它会询问你的帐户名称和两个密钥。使用之前生成的公钥。

确认后账号会被建好。

cleos --url https://jungle.eosio.cr:443 get account ylvdeveloper
permissions:
owner 1: 1 EOS8VMwRNWWHwov4vyzJiq9uTEyzcny8QKXv7CJxGQAwjSTncyv51
active 1: 1 EOS8CCRKHAbhBim6LimdvhhzhEYiKNnLRhuMD1Zqx5Cut52moBRmH
memory:
quota: 161.4 KiB used: 3.365 KiB net bandwidth:
staked: 100.0000 EOS (total stake delegated from account to self)
delegated: 0.0000 EOS (total staked delegated to account from others)
used: 0 bytes
available: 19.12 MiB
limit: 19.12 MiB cpu bandwidth:
staked: 100.0000 EOS (total stake delegated from account to self)
delegated: 0.0000 EOS (total staked delegated to account from others)
used: 0 us
available: 3.826 sec
limit: 3.826 sec producers: <not voted>

现在我们需要为我们的帐户购买一些RAM,因为我们要发布我们的智能合约。在EOS区块链中,RAM市场上有鲸鱼玩公牛,这是另一个有钱的人投机机会。使用EOS Jungle Testnet Faucet将一些EOS代币放入你的帐户。

之后运行cleos system buyram命令购买带有EOS代币的RAM。

cleos --url https://jungle.eosio.cr:443 system buyram ylvdeveloper ylvdeveloper "10 EOS"
3481816ms thread-0 main.cpp:429 create_action ] result: {"binargs":"7055a5516d9576f47055a5516d9576f4a08601000000000004454f5300000000"} arg: {"code":"eosio","action":"buyram","args":{"payer":"ylvdeveloper","receiver":"ylvdeveloper","quant":"10.0000 EOS"}}
executed transaction: 8eb30f6cfced6845e02b134946c7b6d623558f0c1a5ceff135b7e98007da692f 128 bytes 5094 us
# eosio <= eosio::buyram {"payer":"ylvdeveloper","receiver":"ylvdeveloper","quant":"10.0000 EOS"}
# eosio.token <= eosio.token::transfer {"from":"ylvdeveloper","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
# ylvdeveloper <= eosio.token::transfer {"from":"ylvdeveloper","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
# eosio.ram <= eosio.token::transfer {"from":"ylvdeveloper","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
# eosio.token <= eosio.token::transfer {"from":"ylvdeveloper","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
# ylvdeveloper <= eosio.token::transfer {"from":"ylvdeveloper","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
# eosio.ramfee <= eosio.token::transfer {"from":"ylvdeveloper","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
warning: transaction executed locally, but may not be confirmed by the network yet

创建合约

首先,我们必须将我们的合约上传到区块链。Cleos命令set contract通过以下位置参数执行:

* account — the account to publish a contract for.
* contract-dir — contract directory.
* wast-file — the file containing the contract WAST or WASM.
* abi-file — the ABI of the contract.

如你所见,我们需要指定wastabi文件。如果你通过源代码构建EOS,可以在./build/contracts/eosio.token/文件夹中找到它们。为方便起见,我上传了他们两个 wast/abi。 我们用自己的帐户和文件调用set contract命令。因为我们的wast/abi文件与目录名称是相同,所以我们可以跳过这些参数。

cleos --url https://jungle.eosio.cr:443 set contract ylvdeveloper ./contracts/eosio.token
Reading WAST/WASM from ./contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: 3fa704e4c1c72050e61882460bf0acd3b200df087d86a157d3d60ec1c439ba65 8104 bytes 3178 us
# eosio <= eosio::setcode {"account":"ylvdeveloper","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7...
# eosio <= eosio::setabi {"account":"ylvdeveloper","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d6...
warning: transaction executed locally, but may not be confirmed by the network yet

让我们检查代码是否已使用get code ylvdeveloper命令上传。

cleos --url https://jungle.eosio.cr:443 get code ylvdeveloper
code hash: 641f336aa1d08526201599c3c0ddb7a646e5ac8f9fd2493f56414d0422a0f957

创建代币

最后,我们可以创建和发布我们的令牌。我们将使用cleos push action命令利用我们的智能合约的创建和发布,该命令采用以下参数:

* contract — the account providing the contract to execute.
* action — the action to execute on the contract.
* data — the arguments to the contract.

让我们创建YLV代币并发出一些代币。

cleos --url https://jungle.eosio.cr:443 push action ylvdeveloper transfer '{"from":"ylvdeveloper", "to":"ylvio", "quantity":"100.00 YLV", "memo":"gift"}' -p ylvdeveloper
executed transaction: 32abee7e426d9e5653f67a7b492c17ca62aeeef97ff1a86037f58f2dd1459452 136 bytes 1639 us
# ylvdeveloper <= ylvdeveloper::transfer {"from":"ylvdeveloper","to":"ylvio","quantity":"100.00 YLV","memo":"gift"}
# ylvio <= ylvdeveloper::transfer {"from":"ylvdeveloper","to":"ylvio","quantity":"100.00 YLV","memo":"gift"}

检查下余额:

cleos --url https://jungle.eosio.cr:443 get table ylvdeveloper ylvdeveloper accounts
{
"rows": [{
"balance": "900.00 YLV"
}
],
"more": false
}
Bytezilla:build iYalovoy$ cleos --url https://jungle.eosio.cr:443 get table ylvdeveloper ylvio accounts
{
"rows": [{
"balance": "100.00 YLV"
}
],
"more": false
}

按预期完成了我们的工作,很完美。

总结下

我们从安装cleos和了解eosio.token智能合约再到拥有我们自己的代币并将代币转移到其他帐户的全部过程。我们使用EOS Jungle Testnet完成了所有这一切,它几乎与Mainnet相同。相同的步骤适用于Mainnet,你只需使用不同的API节点并为你的帐户和RAM支付相应的费用。

  • EOS代币是一个智能合约。
  • Cleos是用于与钱包和节点交互的命令行实用程序。
  • EOS Jungle Testnet可用于开发。
  • 你可以使用eosio.token智能合约创建,发布和发送你自己的代币。

安利个EOS相关的交互式在线编程实战教程:

EOS教程,本课程帮助你快速入门EOS区块链去中心化应用的开发,内容涵盖EOS工具链、账户与钱包、发行代币、智能合约开发与部署、使用代码与智能合约交互等核心知识点,最后综合运用各知识点完成一个便签DApp的开发。

汇智网原创翻译,转载请标明出处。这里是原文如何创建和部署自己的EOS代币

最新文章

  1. querystring模块
  2. linux下使用rdp
  3. IOS基础之 (一) OC基础语法
  4. Word and MediaElement
  5. ZTE AD3812 3G模块在linux 2.6.34 内核的开发板上的支持方法
  6. HDU_2011——求多项式的前n项和
  7. Zookeeper 4、Zookeeper开发
  8. android布局margin和padding差异!
  9. cookie记忆换肤功能实战Demo
  10. java开发之阿里云对象存储OSS和云数据库Memcache的使用
  11. 执行Android后台任务的最佳实践
  12. spring boot -表单校验步骤 +@NotEmpty,@NotNull和@NotBlank的区别
  13. pip 解决下载包速度慢的问题
  14. Error watching file for changes: EMFILE
  15. 093实战 Nginx日志切割,以及脚本上传nginx的切割日志
  16. 多线程——newFixedThreadPool线程池
  17. (转)处理SQL中的异常并记录错误日志
  18. LOJ #2985. 「WC2019」I 君的商店
  19. CSS3 Transitions属性打造动画的下载按钮特效
  20. MySQL的WHERE语句中BETWEEN与IN的用法和他们的区别

热门文章

  1. binlog的作用及与redo log的区别
  2. Golang Web入门(1):自顶向下理解Http服务器
  3. ssm整合简单例子
  4. Python操作rabbitmq系列(六):进行RPC调用
  5. MD5中使用16进制
  6. C#多线程系列(3):原子操作
  7. SpringBoot实现图片上传demo&amp;Nginx进行代理显示
  8. C++基础的一些代码和笔记 stl乱炖
  9. stand up meeting 11/27/2015-11/29/2015
  10. vue2.x学习笔记(七)