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

相关文章
相关标签/搜索