導航到你的contracts
目錄。git
cd CONTRACTS_DIR
拉取源:github
git clone https://github.com/EOSIO/eosio.contracts --branch v1.4.0 --single-branch
這個存儲庫包含幾個合約,但如今重要的是eosio.token
合約,導航到該目錄。json
cd eosio.contracts/eosio.token
在咱們部署代幣合約以前,咱們必須建立一個賬戶來部署它,咱們將爲該賬戶使用eosio開發密鑰。segmentfault
你可能必須首先解鎖你的錢包!
cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
eosio-cpp -I include -o eosio.token.wasm src/eosio.token.cpp --abigen
cleos set contract eosio.token CONTRACTS_DIR/eosio.contracts/eosio.token --abi eosio.token.abi -p eosio.token@active
響應:code
Reading WASM from ... Publishing contract... executed transaction: 69c68b1bd5d61a0cc146b11e89e11f02527f24e4b240731c4003ad1dc0c87c2c 9696 bytes 6290 us # eosio <= eosio::setcode {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d0100000001aa011c60037f7e7f0060047f... # eosio <= eosio::setabi {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e30000605636c6f73650002056f776e6572046e61... warning: transaction executed locally, but may not be confirmed by the network yet ]
要建立新代幣,請使用正確的參數調用create(...)
操做,此操做接受1個參數,它是一個symbol_name
類型,由兩個數據組成,最大供應的浮點數和僅大寫字母字符的symbol_name
,例如「1.0000 SYM」,發行人將是有權要求發行或執行其餘操做,如凍結、召回和列入全部者的白名單。token
下面是使用位置參數調用此方法的簡明方法:開發
cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' -p eosio.token@active
響應:部署
executed transaction: 0e49a421f6e75f4c5e09dd738a02d3f51bd18a0cf31894f68d335cd70d9c0e12 120 bytes 1000 cycles # eosio.token <= eosio.token::create {"issuer":"eosio","maximum_supply":"1000000000.0000 SYS"}
另外一種方法使用命名參數:get
cleos push action eosio.token create '{"issuer":"eosio", "maximum_supply":"1000000000.0000 SYS"}' -p eosio.token@active
響應:it
executed transaction: 0e49a421f6e75f4c5e09dd738a02d3f51bd18a0cf31894f68d335cd70d9c0e12 120 bytes 1000 cycles # eosio.token <= eosio.token::create {"issuer":"eosio","maximum_supply":"1000000000.0000 SYS"}
此命令建立了一個新的代幣SYS
,其精度爲4位小數,最大供應量爲1000000000.0000 SYS,要建立此代幣,須要得到eosio.token
合約的許可,所以,傳遞了-p eosio.token@active
以受權請求。
發行者能夠向以前建立的「alice」賬戶發放新代幣。
cleos push action eosio.token issue '[ "alice", "100.0000 SYS", "memo" ]' -p eosio@active
響應:
executed transaction: 822a607a9196112831ecc2dc14ffb1722634f1749f3ac18b73ffacd41160b019 268 bytes 1000 cycles # eosio.token <= eosio.token::issue {"to":"user","quantity":"100.0000 SYS","memo":"memo"} >> issue # eosio.token <= eosio.token::transfer {"from":"eosio","to":"user","quantity":"100.0000 SYS","memo":"memo"} >> transfer # eosio <= eosio.token::transfer {"from":"eosio","to":"user","quantity":"100.0000 SYS","memo":"memo"} # user <= eosio.token::transfer {"from":"eosio","to":"user","quantity":"100.0000 SYS","memo":"memo"}
此次輸出包含幾個不一樣的操做:一個發行和三個轉移,雖然簽名的惟一操做是issue
,但issue
操做執行了「內聯轉移」,「內聯轉移」通知了發件人和收件人賬戶,輸出指示被調用的全部操做處理程序、調用它們的順序以及操做是否生成任何輸出。
從技術上講,eosio.token
合約可能會跳過inline transfer
並選擇直接修改餘額,可是,在這種狀況下,eosio.token
合約遵循咱們的代幣約定,該約定要求全部賬戶餘額能夠經過引用它們的轉移操做的總和來推導,它還要求通知資金的發送方和接收方,以便它們能夠自動處理存款和取款。
要檢查交易,請嘗試使用-d -j
選項,它們表示「不要廣播」和「將交易返回爲json」,這在開發過程當中可能會有用。
cleos push action eosio.token issue '["alice", "100.0000 SYS", "memo"]' -p eosio@active -d -j
如今alice
賬戶已經發行了代幣,將其中一些轉移到賬戶bob
,以前使用參數-p alice@active
表示alice
受權此操做。
cleos push action eosio.token transfer '[ "alice", "bob", "25.0000 SYS", "m" ]' -p alice@active
響應:
executed transaction: 06d0a99652c11637230d08a207520bf38066b8817ef7cafaab2f0344aafd7018 268 bytes 1000 cycles # eosio.token <= eosio.token::transfer {"from":"alice","to":"bob","quantity":"25.0000 SYS","memo":"Here you go bob!"} >> transfer # user <= eosio.token::transfer {"from":"alice","to":"bob","quantity":"25.0000 SYS","memo":"Here you go bob!"} # tester <= eosio.token::transfer {"from":"alice","to":"bob","quantity":"25.0000 SYS","memo":"Here you go bob!"}
如今使用cleos get currency balance
檢查「bob」是否得到代幣。
cleos get currency balance eosio.token bob SYS 25.00 SYS
檢查「alice」的餘額,注意從賬戶中扣除了代幣。
cleos get currency balance eosio.token alice SYS 75.00 SYS