Deploy, Issue and Transfer Tokens

Deploy, Issue and Transfer Tokensgit

  本例使用 eosio.token 合約來嘗試發行Token.github

一、簽出 eosio.contracts。json

git clone https://github.com/EOSIO/eosio.contracts --branch v1.4.0 --single-branch

  這裏頭有不少eosio寫的標準合約。ubuntu

  

  咱們將使用上圖中的 eosio.token 合約來練習發佈 token。api

二、eosio.token很是的簡單,僅包含 eosio.token.hpp、eosio.token.cpp兩件文件。其中提供了6個action:ui

  

三、創建一個 eosio.token account,此帳戶用於發佈eosio.token合約。this

cleos create account eosio eosio.token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

四、在 eosio.token 目錄下編譯合約 spa

eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp --abigen

五、用 eosio.token 帳號發佈合約 code

cleos set contract eosio.token /home/ubuntu/contracts/eosio.contracts/eosio.token --abi eosio.token.abi -p eosio.token@active

六、一個合約能夠建立多個token。使用 create 方法建立一種token。orm

cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' -p eosio.token@active

  由於此處是建立token,因此須要 eosio.token 帳戶的權限。

  it's a symbol_name type composed of two pieces of data, a maximum supply float and a symbol_name in capitalized alpha characters only, for example "1.0000 SYM".

  The issuer will be the one with authority to call issue and or perform other actions such as freezing, recalling, and whitelisting of owners.

 

  This command created a new token SYS with a precision of 4 decimals and a maximum supply of 1000000000.0000 SYS. To create this token requires the permission of the eosio.token contract. For this reason, -p eosio.token@active was passed to authorize the request.

七、發行token。

  The issuer can issue new tokens to the "alice" account created earlier.

  發行者(issuer)能夠給其它用戶發行token。

cleos push action eosio.token issue '[ "alice", "100.0000 SYS", "memo" ]' -p eosio@active

  注意,由於此處是發行token,因此須要發行者(issuer)的權限。

  

  To inspect the transaction, try using the -d -j options, they indicate "don't broadcast" and "return transaction as json," which you may find useful during development.

cleos push action eosio.token issue '["alice", "100.0000 SYS", "memo"]' -p eosio@active -d -j

八、轉移 token。

cleos push action eosio.token transfer '[ "alice", "bob", "25.0000 SYS", "m" ]' -p alice@active

  Now check if "bob" got the tokens using cleos get currency balance

cleos get currency balance eosio.token bob SYS
25.00 SYS

  Check "alice's" balance, notice that tokens were deducted from the account

cleos get currency balance eosio.token alice SYS
75.00 SYS

 

參考:

一、https://developers.eos.io/eosio-home/docs/token-contract#section-step-3-compile-the-contract

相關文章
相關標籤/搜索