代币开发

1. 启动nodeos服务,这个服务主要用来干什么?
./nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin


  -e [ --enable-stale-production ]      Enable block production, even if the
                                        chain is stale.
  -p [ --producer-name ] arg            ID of producer controlled by this node
                                        (e.g. inita; may specify multiple
                                        times)


2. 钱包必须open之后,才能查询得到
./cleos wallet open -n  wangWallet
./cleos wallet list

3. 解锁钱包
 ./cleos wallet unlock -n wangWallet

4. 查看钱包里存放的公钥
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ ./cleos wallet keys
[
  "EOS5iHksSoK2fvfKxuysstSvcy3dAADGUmedXXWmsGLGr6YwQjrdk",
  "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  "EOS736mLSB8RxnvaAD3tbaao8TsKPsntF21hyATgoogMXqZw1HceX"
]

4.
(1)创建一个账户
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos create account eosio eosio.token EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV  EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
executed transaction: 2ecb4ece1121e3ef99be6e9ca35bf2ffcb9d268ca16f07a8384be57652cb25b3  200 bytes  225 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"eosio.token","owner":{"threshold":1,"keys":[{"key":"EOS6MRyAjQq8ud7hVNYcf...
warning: transaction executed locally, but may not be confirmed by the network yet
可以看到账户的创建者叫做eosio,账户的名称叫做eosio.token, 它的公钥是EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

(2)查看公钥对应的账户
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ ./cleos get accounts EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
{
  "account_names": []
}

5. 部署合约-----部署合约需要创建一个账户,参考第4步。
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos set contract eosio.token ../../contracts/eosio.token -p eosio.token
Reading WAST/WASM from ../../contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: d57b5643f20c071212a133c77057bc659f0c23e6c17be61e3cb410b1d5a4216e  8104 bytes  33212 us
#         eosio <= eosio::setcode               {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7e...
#         eosio <= eosio::setabi                {"account":"eosio.token","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d65...
warning: transaction executed locally, but may not be confirmed by the network yet
这里的意思是给eosio.token账户部署../../contracts/eosio.token合约,这个合约主要用来发行呆逼,它能使不同的代币跑在相同的合约上,但是被不同的用户管理。


6. 截止现在账户也有了,基础的eosio.token合约也部署了,就可以创建代币了。可以从源码中看到,它提供了以下几个接口,如果需要开发新的接口,只需要在这里修改源码,并且增加相应的实现就可以了,这就是二次开发。
(1)源码如下
ubuntu@ubuntu:~/coding/eos/contracts/eosio.token$ cat eosio.token.hpp
/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
#pragma once

#include <eosiolib/asset.hpp>
#include <eosiolib/eosio.hpp>

#include <string>

namespace eosiosystem {
   class system_contract;
}

namespace eosio {

   using std::string;

   class token : public contract {
      public:
         token( account_name self ):contract(self){}

         void create( account_name issuer,
                      asset        maximum_supply);

         void issue( account_name to, asset quantity, string memo );

         void transfer( account_name from,
                        account_name to,
                        asset        quantity,
                        string       memo );
      
      
         inline asset get_supply( symbol_name sym )const;
         
         inline asset get_balance( account_name owner, symbol_name sym )const;


(2) push一个action(action就是创建、转账、余额查询等)到区块链上
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ ./cleos push action
ERROR: RequiredError: account
Push a transaction with a single action
Usage: ./cleos push action [OPTIONS] account action data

ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' -p eosio.token
Error 3080006: transaction took too long
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos push action eosio.token create '[ "eosio", "1000000000.0000 EOS"]' -p eosio.token
Error 3080006: transaction took too long
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' -p eosio.token
executed transaction: 8f8c28795b336fa7cc2eacfd07c1bb1b30897766ae38d5a8168b695668243fbe  120 bytes  328 us
#   eosio.token <= eosio.token::create          {"issuer":"eosio","maximum_supply":"1000000000.0000 SYS"}
warning: transaction executed locally, but may not be confirmed by the network yet
这里发行代币,账户为eosio,这里的账户名为账户创建者,10亿个代币,名称叫做SYS币,这里有个bug,如果第一次创建不成功,那么可以将SYS改一个名字,然后再换回SYS进行创建,这个问题肯定是个bug,需要定位,但是处于学习阶段,还是先进行主框架的学习。


7. 发行代币。上面创建的10亿个代币都是eosio持有,现在发行给叫做user的用户。
(1)再创建一个账户,用来接受货币:
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos create account eosio user EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
executed transaction: 0b40d9a736cf03f95e9b89fe41bbcf9bcd32839fb190ebcb49c6e651bb939459  200 bytes  190 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"user","owner":{"threshold":1,"keys":[{"key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcV...
warning: transaction executed locally, but may not be confirmed by the network yet
(2)发放代币给另一个用户
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos push action eosio.token issue '[ "user", "100.0000 SYS", "memo" ]' -p eosio
executed transaction: 145b9547c397029e86f8142b0ba53fd5d8fcf0b7fcf3cbdd9b3c8278119909c9  128 bytes  884 us
#   eosio.token <= eosio.token::issue           {"to":"user","quantity":"100.0000 SYS","memo":"memo"}
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"user","quantity":"100.0000 SYS","memo":"memo"}
#         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"}
warning: transaction executed locally, but may not be confirmed by the network yet


8. 转账。
(1)再创建一个tester账户,实现从user账户转账到tester账户。
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos create account eosio tester EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
executed transaction: bf51285b8e81309e44fc96b890015b729f770929f928e7a1e067ccbc2a1a2d2b  200 bytes  206 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"tester","owner":{"threshold":1,"keys":[{"key":"EOS6MRyAjQq8ud7hVNYcfnVPJq...
warning: transaction executed locally, but may not be confirmed by the network yet
(2)转账
ubuntu@ubuntu:~/coding/eos/build/programs/cleos$ cleos push action eosio.token transfer '[ "user", "tester", "25.0000 SYS", "m" ]' -p user
executed transaction: 2f6ddfd7a40f7793dfd9f588c93c1758e7cc97d4432404bec6953d6c0c605079  128 bytes  485 us
#   eosio.token <= eosio.token::transfer        {"from":"user","to":"tester","quantity":"25.0000 SYS","memo":"m"}
#          user <= eosio.token::transfer        {"from":"user","to":"tester","quantity":"25.0000 SYS","memo":"m"}
#        tester <= eosio.token::transfer        {"from":"user","to":"tester","quantity":"25.0000 SYS","memo":"m"}
warning: transaction executed locally, but may not be confirmed by the network yet

至此本节已经讲完了最基础的功能。下一节我们接着讲进一步的功能。

猜你喜欢

转载自blog.csdn.net/wangping623/article/details/80924547
今日推荐