如何建立和部署一個屬於本身的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工具鏈、帳戶與錢包、發行代幣、智能合約開發與部署、使用代碼與智能合約交互等核心知識點,最後綜合運用各知識點完成一個便籤DApp的開發。

匯智網原創翻譯,轉載請標明出處。這裏是原文如何建立和部署本身的EOS代幣

相關文章
相關標籤/搜索