如何創建和部署一個屬於自己的EOS代幣 原

本文我們將弄清楚什麼是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工具鏈、賬戶與錢包、發行代幣、智能合約開發與部署、使用代碼與智能合約交互等核心知識點,最後綜合運用各知識點完成一個便籤DApp的開發。

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章