您正在查看: EOS-新手教程 分类下的文章

获取EOS实时价格 USD price

http api:https://api.coinmarketcap.com/v2/ticker/1765/

{
    "data": {
        "id": 1765, 
        "name": "EOS", 
        "symbol": "EOS", 
        "website_slug": "eos", 
        "rank": 5, 
        "circulating_supply": 906245118, 
        "total_supply": 1006245120, 
        "max_supply": 1000000000, 
        "quotes": {
            "USD": {
                "price": 7.1827637594, 
                "volume_24h": 636473463.658721, 
                "market_cap": 6509344588, 
                "percent_change_1h": -0.09, 
                "percent_change_24h": -1.29, 
                "percent_change_7d": -16.8
            }
        }, 
        "last_updated": 1533193294
    }, 
    "metadata": {
        "timestamp": 1533192860, 
        "error": null
    }
}

https://api.coinmarketcap.com/v1/ticker/${symbol}/?convert=${convert_symbol}
price字段即为当前的EOS USD价格 (具体准确度,自己衡量)
数据来自:github erp

EOS 获取资源抵押赎回数据

用户可以根据需要,自己或者别人帮助抵押EOS,获取NET或者CPU资源。
查看此时账户bcskillsurou信息

root@iZj6cbx3duprxf6dasczbpZ:~# cleos -u http://167.99.91.77:8888 get account bcskillsurou
permissions: 
     owner     1:    1 EOS8127zAiVVtPMJoiXyX8oLiReNaj32VBsJXKuTLkJsQyubKcSt7
        active     1:    1 EOS6Zfj72f6kBVZQrbkcCCGhWGnUfkmFBZ6b4Ya76GVunTanVYhtC
memory: 
     quota:     50.88 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:        18.78 MiB  
     limit:            18.78 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.751 sec  
     limit:            3.751 sec  

EOS balances: 
     liquid:        10000.0000 EOS
     staked:          200.0000 EOS
     unstaking:         0.0000 EOS
     total:         10200.0000 EOS

producers:     <not voted>

对于账户抵押分为stakeddelegated

  • staked:自己给自己抵押,或者别人给你抵押时移交了币的所属(添加参数 --transfer
  • delegated:别人帮你抵押的,币的所属权归对方。

下面演示抵押测试

先让dappplaytestbcskillsurou NET和CPU各抵押10EOS,不转移币的所有权

root@iZj6cbx3duprxf6dasczbpZ:~# cleos -u http://167.99.91.77:8888 system delegatebw dappplaytest bcskillsurou "10 EOS" "10 EOS"
3081849ms thread-0   main.cpp:438                  create_action        ] result: {"binargs":"90b1cadec45aab49a0e9d5384607313aa08601000000000004454f5300000000a08601000000000004454f530000000000"} arg: {"code":"eosio","action":"delegatebw","args":{"from":"dappplaytest","receiver":"bcskillsurou","stake_net_quantity":"10.0000 EOS","stake_cpu_quantity":"10.0000 EOS","transfer":false}} 
executed transaction: ff8d82345bfb095bec396f258c62ee5c244577828993da26abb94e7deff5deb1  144 bytes  3307 us
#         eosio <= eosio::delegatebw            {"from":"dappplaytest","receiver":"bcskillsurou","stake_net_quantity":"10.0000 EOS","stake_cpu_quant...
#   eosio.token <= eosio.token::transfer        {"from":"dappplaytest","to":"eosio.stake","quantity":"20.0000 EOS","memo":"stake bandwidth"}
#  dappplaytest <= eosio.token::transfer        {"from":"dappplaytest","to":"eosio.stake","quantity":"20.0000 EOS","memo":"stake bandwidth"}
#   eosio.stake <= eosio.token::transfer        {"from":"dappplaytest","to":"eosio.stake","quantity":"20.0000 EOS","memo":"stake bandwidth"}

查看bcskillsurou账户信息

root@iZj6cbx3duprxf6dasczbpZ:~# cleos -u http://167.99.91.77:8888 get account bcskillsurou
permissions: 
     owner     1:    1 EOS8127zAiVVtPMJoiXyX8oLiReNaj32VBsJXKuTLkJsQyubKcSt7
        active     1:    1 EOS6Zfj72f6kBVZQrbkcCCGhWGnUfkmFBZ6b4Ya76GVunTanVYhtC
memory: 
     quota:     50.88 KiB    used:     3.365 KiB  

net bandwidth: 
     staked:        100.0000 EOS           (total stake delegated from account to self)
     delegated:      10.0000 EOS           (total staked delegated to account from others)
     used:                 0 bytes
     available:        20.66 MiB  
     limit:            20.66 MiB  

cpu bandwidth:
     staked:        100.0000 EOS           (total stake delegated from account to self)
     delegated:      10.0000 EOS           (total staked delegated to account from others)
     used:                 0 us   
     available:        4.126 sec  
     limit:            4.126 sec  

EOS balances: 
     liquid:        10000.0000 EOS
     staked:          200.0000 EOS
     unstaking:         0.0000 EOS
     total:         10200.0000 EOS

NET和CPU的delegated 都显示了新转的10EOS
查看EOSpark,显示的是staked + delegated总抵押,并没有区分。

下面演示取消抵押测试

对于delegated只能抵押方撤回抵押

root@iZj6cbx3duprxf6dasczbpZ:~# cleos -u http://167.99.91.77:8888 system undelegatebw dappplaytest bcskillsurou "2 EOS" "2 EOS"
3549315ms thread-0   main.cpp:438                  create_action        ] result: {"binargs":"90b1cadec45aab49a0e9d5384607313a204e00000000000004454f5300000000204e00000000000004454f5300000000"} arg: {"code":"eosio","action":"undelegatebw","args":{"from":"dappplaytest","receiver":"bcskillsurou","unstake_net_quantity":"2.0000 EOS","unstake_cpu_quantity":"2.0000 EOS"}} 
executed transaction: db39983263b7e81f758360d62a1e62fa605d7f14abee288def78996e160f0e28  184 bytes  2437 us
#         eosio <= eosio::undelegatebw          {"from":"dappplaytest","receiver":"bcskillsurou","unstake_net_quantity":"2.0000 EOS","unstake_cpu_qu...

查看bcskillsurou账户信息

root@iZj6cbx3duprxf6dasczbpZ:~# cleos -u http://167.99.91.77:8888 get account bcskillsurou
permissions: 
     owner     1:    1 EOS8127zAiVVtPMJoiXyX8oLiReNaj32VBsJXKuTLkJsQyubKcSt7
        active     1:    1 EOS6Zfj72f6kBVZQrbkcCCGhWGnUfkmFBZ6b4Ya76GVunTanVYhtC
memory: 
     quota:     50.88 KiB    used:     3.365 KiB  

net bandwidth: 
     staked:        100.0000 EOS           (total stake delegated from account to self)
     delegated:       8.0000 EOS           (total staked delegated to account from others)
     used:                 0 bytes
     available:        20.28 MiB  
     limit:            20.28 MiB  

cpu bandwidth:
     staked:        100.0000 EOS           (total stake delegated from account to self)
     delegated:       8.0000 EOS           (total staked delegated to account from others)
     used:                 0 us   
     available:        4.051 sec  
     limit:            4.051 sec  

EOS balances: 
     liquid:        10000.0000 EOS
     staked:          200.0000 EOS
     unstaking:         0.0000 EOS
     total:         10200.0000 EOS

producers:     <not voted>

CPU和NET delegated 都减少了2EOS

对于staked自己撤回抵押

root@iZj6cbx3duprxf6dasczbpZ:~# cleos -u http://167.99.91.77:8888 system undelegatebw bcskillsurou bcskillsurou "2 EOS" "2 EOS"
271082ms thread-0   main.cpp:438                  create_action        ] result: {"binargs":"a0e9d5384607313aa0e9d5384607313a204e00000000000004454f5300000000204e00000000000004454f5300000000"} arg: {"code":"eosio","action":"undelegatebw","args":{"from":"bcskillsurou","receiver":"bcskillsurou","unstake_net_quantity":"2.0000 EOS","unstake_cpu_quantity":"2.0000 EOS"}} 
executed transaction: f5f05f18655f4ded25ad8f8d56b6b3b0dfc340c6fd017019e9ca05612149554a  184 bytes  2209 us
#         eosio <= eosio::undelegatebw          {"from":"bcskillsurou","receiver":"bcskillsurou","unstake_net_quantity":"2.0000 EOS","unstake_cpu_qu...

查看bcskillsurou账户信息

root@iZj6cbx3duprxf6dasczbpZ:~# cleos -u http://167.99.91.77:8888 get account bcskillsurou
permissions: 
     owner     1:    1 EOS8127zAiVVtPMJoiXyX8oLiReNaj32VBsJXKuTLkJsQyubKcSt7
        active     1:    1 EOS6Zfj72f6kBVZQrbkcCCGhWGnUfkmFBZ6b4Ya76GVunTanVYhtC
memory: 
     quota:     50.88 KiB    used:     3.951 KiB  

net bandwidth: 
     staked:         98.0000 EOS           (total stake delegated from account to self)
     delegated:       8.0000 EOS           (total staked delegated to account from others)
     used:               185 bytes
     available:        19.91 MiB  
     limit:            19.91 MiB  

cpu bandwidth:
     staked:         98.0000 EOS           (total stake delegated from account to self)
     delegated:       8.0000 EOS           (total staked delegated to account from others)
     used:             5.182 ms   
     available:        3.971 sec  
     limit:            3.976 sec  

unstaking tokens:
     time of unstake request:  2018-08-02T06:04:32 (funds will be available in 71.99 hr)
     from net bandwidth:              2.0000 EOS
     from cpu bandwidth:              2.0000 EOS
     total:                           4.0000 EOS

EOS balances: 
     liquid:        10000.0000 EOS
     staked:          196.0000 EOS
     unstaking:         4.0000 EOS
     total:         10200.0000 EOS

producers:     <not voted>

CPU和NET staked 都减少了2EOS

总结

获取当前账号下NET或CPU抵押数 分别等于staked + delegated
获取当前账号下NET或CPU赎回数和赎回时的当前时间(只显示最后一次发起时间)查看 unstaking tokens字段 (3天后完成)

RPC返回数据
{
    "account_name": "bcskillsurou", 
    "head_block_num": 7878445, 
    "head_block_time": "2018-08-02T06:18:01.500", 
    "privileged": false, 
    "last_code_update": "1970-01-01T00:00:00.000", 
    "created": "2018-08-02T04:25:06.500", 
    "core_liquid_balance": "10000.0000 EOS", 
    "ram_quota": 52098, 
    "net_weight": 1060000, 
    "cpu_weight": 1060000, 
    "net_limit": {
        "used": 185, 
        "available": 20873227, 
        "max": 20873412
    }, 
    "cpu_limit": {
        "used": 5182, 
        "available": 3970991, 
        "max": 3976173
    }, 
    "ram_usage": 4046, 
    "permissions": [
        {
            "perm_name": "active", 
            "parent": "owner", 
            "required_auth": {
                "threshold": 1, 
                "keys": [
                    {
                        "key": "EOS6Zfj72f6kBVZQrbkcCCGhWGnUfkmFBZ6b4Ya76GVunTanVYhtC", 
                        "weight": 1
                    }
                ], 
                "accounts": [ ], 
                "waits": [ ]
            }
        }, 
        {
            "perm_name": "owner", 
            "parent": "", 
            "required_auth": {
                "threshold": 1, 
                "keys": [
                    {
                        "key": "EOS8127zAiVVtPMJoiXyX8oLiReNaj32VBsJXKuTLkJsQyubKcSt7", 
                        "weight": 1
                    }
                ], 
                "accounts": [ ], 
                "waits": [ ]
            }
        }
    ], 
    "total_resources": {
        "owner": "bcskillsurou", 
        "net_weight": "106.0000 EOS", 
        "cpu_weight": "106.0000 EOS", 
        "ram_bytes": 52098
    }, 
    "self_delegated_bandwidth": {
        "from": "bcskillsurou", 
        "to": "bcskillsurou", 
        "net_weight": "98.0000 EOS", 
        "cpu_weight": "98.0000 EOS"
    }, 
    "refund_request": {
        "owner": "bcskillsurou", 
        "request_time": "2018-08-02T06:04:32", 
        "net_amount": "2.0000 EOS", 
        "cpu_amount": "2.0000 EOS"
    }, 
    "voter_info": {
        "owner": "bcskillsurou", 
        "proxy": "", 
        "producers": [ ], 
        "staked": 1960000, 
        "last_vote_weight": "0.00000000000000000", 
        "proxied_vote_weight": "0.00000000000000000", 
        "is_proxy": 0
    }
}

相对于cleos Rpc返回的数据要清晰一些

  • CPU或NET的总抵押等于cleos中的staked + delegated
    total_resources["net_weight"] NET的总抵押,
    total_resources["cpu_weight"] CPU的总抵押
  • CPU或者NET属于自己的抵押,等于cleos中的staked
    self_delegated_bandwidth["net_weight"] NET的自己抵押,
    self_delegated_bandwidth["cpu_weight"] CPU的自己抵押
  • 赎回信息
    refund_request["request_time"] 最后发起的赎回时间,3天后抵押EOS到账。
    refund_request["net_amount"] NET总赎回
    refund_request["cpu_amount"] CPU总赎回

    参考

    测试网测试方法参考(EOSpark EOS浏览器 + EOS Jungle Testnet

EOSpark EOS浏览器 + EOS Jungle Testnet

测试EOS交易等数据时,必不可少的需要一款EOS浏览器方便查看相关的数据。
目前我没有全方面的测试,只测过4-5款,目前来说EOSpark从数据展示,交互,响应速度都能满足我的需求,大家有什么推荐的可以留言。
本文主要讲的是,EOSpark支持EOS Jungle Testnet测试网,在测试网中,可以免费领取大量EOS测试币(6h/10000),方便测试中不必要的消耗。

下面演示如果在EOS Jungle Testnet测试网中创建账号,申请EOS测试币,并在EOSpark浏览器显示账号信息。

  • 打开EOS Jungle Testnet网站(点击打开)此时版本 V0.5.7
  • 点击 Create Account,输入账户名,owner和active的公钥,点击创建
  • 点击Faucet获取EOS测试币

在EOSpark浏览器中查看账号

  • 打开EOSpark浏览器官网(点击打开),切换Jungle Testnet测试网络
  • 查看刚才在Jungle Testnet测试网络中新建的bcskillsurou账号

cleos get account

root@iZj6cbx3duprxf6dasczbpZ:~# cleos -u http://167.99.91.77:8888 get account bcskillsurou
permissions: 
     owner     1:    1 EOS8127zAiVVtPMJoiXyX8oLiReNaj32VBsJXKuTLkJsQyubKcSt7
        active     1:    1 EOS6Zfj72f6kBVZQrbkcCCGhWGnUfkmFBZ6b4Ya76GVunTanVYhtC
memory: 
     quota:     50.88 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:        18.78 MiB  
         limit:            18.78 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.751 sec  
         limit:            3.751 sec  

    EOS balances: 
         liquid:        10000.0000 EOS
         staked:          200.0000 EOS
         unstaking:         0.0000 EOS
         total:         10200.0000 EOS

    producers:     <not voted>

使用CLion查看EOS代码

本文将会介绍如何使用CLion查看EOS源码。

EOS的智能合约基于C++开发,官方在github上提供了很多合约样例,地址: https://github.com/EOSIO/eos/tree/master/contracts

直接查看这些样例的源码无疑是学习合约开发最快速的方法,这时我们需要一个合适的IDE工具,尤其是IDE的代码追查功能,能够大大提高阅读源码的效率,在这推荐大家使用CLion。

Clion简介

CLion是一款专为开发C及C++所设计的跨平台IDE。由大名鼎鼎的JetBrains公司开发,以IntelliJ为基础设计,支持Linux、macOS及Windows平台。

下载地址:https://www.jetbrains.com/clion/download/

CLion需要收费,初次下载有30天的免费试用期。

编译EOS源码

在使用CLion之前,需要先编译eos源码,这样才能在导入源码之后使用IDE的代码追查功能。
eos提供了自动编译脚本,一键傻瓜式操作。下载源码后,进入eos目录,运行自动编译脚本。

cd eos
./eosio_build.sh

编译过程中会根据当前系统环境,下载相关依赖,以MacOS为例,有如下依赖。

如果这些依赖不存在,会自动下载并且安装,编译成功后会显示下面的内容。

安装生成文件

cd build
sudo make install

导入EOS源码到CLion
启动CLion,选择Import Project from Sources导入eos目录中的内容

导入时,会提示eos目录下已有CMakeList.txt文件,点击 Open Project按钮。

导入后,CLion需要根据CmakeLists.txt文件编译整个项目,在CMake窗口会显示当前的编译进度,如果编译完成后,能够如下图显示[Finished]并且没有报任何错误,那么恭喜你导入成功,接下来就可以愉快的阅读源码了。

常见问题

系统:MacOS 10.13.3

  • Failed to find Gettext libintl (missing: Intl_INCLUDE_DIR)
    解决方案
    brew unlink gettext && brew link --force gettext
    find /usr -name libintl* -print 2>/dev/null
  • Unable to find the requested Boost libraries
    错误信息:
    Unable to find the requested Boost libraries.
    Unable to find the Boost header files.  Please set BOOST_ROOT to the root
    directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.

    解决方案

    brew uninstall boost
    brew install boost

    进入CLion,重新编译项目。在项目名称上右键,选择“Reload CMake Project”

  • Could not find a package configuration file provided by “LLVM”.
    错误信息:
    Could not find a package configuration file provided by "LLVM" (requested version 4.0) with any of the following names:
    LLVMConfig.cmake
    llvm-config.cmake
    Add the installation prefix of "LLVM" to CMAKE_PREFIX_PATH or set "LLVM_DIR" to a directory containing one of the above files.  If "LLVM" provides a separate development package or SDK, be sure it has been installed.

    解决方案: 首先确保已经安装了llvm,通过下面的命令确认llvm版本信息。

    brew info llvm

    如果已经正确安装,打开CLion的设置页面(command + ,),找到cmake的环境配置。

    在Environment中指定LLVM_DIR,对应llvm的本地路径,例如: LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm
    设置完成后重新编译项目。
    转载自:Tao's Blog

买卖内存的最小字节数 (token amount received from selling ram is too low)

当卖内存字节数按当时内存价格所值的EOS数,如果小于0.0001,则交易出错

root@iZj6cbx3duprxf6dasczbpZ:~# cleos system sellram dapp.exec 1
1483958ms thread-0   main.cpp:438                  create_action        ] result: {"binargs":"000040aa2b50ab490100000000000000"} arg: {"code":"eosio","action":"sellram","args":{"account":"dapp.exec","bytes":1}} 
Error 3050003: eosio_assert_message assertion failure
Error Details:
assertion failure with message: token amount received from selling ram is too low
pending console output:
void system_contract::sellram( account_name account, int64_t bytes ) {
      require_auth( account );
      eosio_assert( bytes > 0, "cannot sell negative byte" );

      user_resources_table  userres( _self, account );
      auto res_itr = userres.find( account );
      eosio_assert( res_itr != userres.end(), "no resource row" );
      eosio_assert( res_itr->ram_bytes >= bytes, "insufficient quota" );

      asset tokens_out;
      auto itr = _rammarket.find(S(4,RAMCORE));
      _rammarket.modify( itr, 0, [&]( auto& es ) {
          /// the cast to int64_t of bytes is safe because we certify bytes is <= quota which is limited by prior purchases
          tokens_out = es.convert( asset(bytes,S(0,RAM)), CORE_SYMBOL);
      });

      eosio_assert( tokens_out.amount > 1, "token amount received from selling ram is too low" );

当按EOS买内存时,如果所支出的EOS扣除0.5%手续费后的余额,按当时内存价格所购买的字节数小于1,则出错"must reserve a positive amount"

void system_contract::buyram( account_name payer, account_name receiver, asset quant )
   {
      require_auth( payer );
      eosio_assert( quant.amount > 0, "must purchase a positive amount" );

      auto fee = quant;
      fee.amount = ( fee.amount + 199 ) / 200; /// .5% fee (round up)
      // fee.amount cannot be 0 since that is only possible if quant.amount is 0 which is not allowed by the assert above.
      // If quant.amount == 1, then fee.amount == 1,
      // otherwise if quant.amount > 1, then 0 < fee.amount < quant.amount.
      auto quant_after_fee = quant;
      quant_after_fee.amount -= fee.amount;
      // quant_after_fee.amount should be > 0 if quant.amount > 1.
      // If quant.amount == 1, then quant_after_fee.amount == 0 and the next inline transfer will fail causing the buyram action to fail.

      INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)},
         { payer, N(eosio.ram), quant_after_fee, std::string("buy ram") } );

      if( fee.amount > 0 ) {
         INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)},
                                                       { payer, N(eosio.ramfee), fee, std::string("ram fee") } );
      }

      int64_t bytes_out;

      const auto& market = _rammarket.get(S(4,RAMCORE), "ram market does not exist");
      _rammarket.modify( market, 0, [&]( auto& es ) {
          bytes_out = es.convert( quant_after_fee,  S(0,RAM) ).amount;
      });

      eosio_assert( bytes_out > 0, "must reserve a positive amount" );

当按字节数买内存时,内部会先按当时内存价格计算出所需的EOS价格,如果计算出的EOS扣除0.5%手续费后的余额,按当时内存价格所购买的字节数小于1,也会出错"must reserve a positive amount"