如何建立和部署本身的EOS代币

本文咱们将弄清楚什么是EOS代币以及如何本身建立和部署EOS代币。node

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

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的节点。github

安装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客户端链接在一块儿,它们展现了这种模式。api

让咱们建立一个名为“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代币

相关文章
相关标签/搜索