EOS RPC获取常见资源数据

https://www.bcskill.com/index.php/archives/353.html

通过get_account 返回信息,屏显账户 cpu,net,ram,抵押,余额,投票,赎回等信息 

https://api.eosarabia.net/v1/chain/get_account
{"account_name": "eoseouldotio" }
可用余额         core_liquid_balance 
抵押                net net_weight/10000  
抵押                cpu cpu_weight/10000 

抵押 net   self_delegated_bandwidth.net_weight  
抵押 cpu  self_delegated_bandwidth.cpu_weight 

ram (KB)
total_resources.ram_bytes  实际买的RAM 大小
ram_quota      是 实际买的RAM 加上了 赠送的 ram_gift_bytes(等于1400)
ram_quota /1024                           总ram
(ram_quota - ram_usage)/1024  已使用 ram

net (KB)
net_limit.max/1024         总net
net_limit.available/1024 剩余net

cpu (us)
cpu_limit.max          总 
cpu_limit.available  剩余
account_name账户名
head_block_num头块号
head_block_time头块时间
privileged是否超级账户,默认false。账户的属性之一
last_code_update最后的code修改时间,例如给账户set contract的时间。账户的属性之一
created账户创建时间。账户的属性之一
core_liquid_balance主币的余额
ram_quota内存限额
net_weight网络带宽资源权重
cpu_weightcpu资源权重
net_limit网络带宽资源,包括已使用、剩余可用、总量
cpu_limitcpu带宽资源,包括已使用、剩余可用、总量
ram_usage内存已使用量
permissions账户的权限内容(账户多签名部分有详细介绍),在状态主库的表里查到的
total_resources总资源量,包括网络、cpu、内存资源总量。在userres状态表里查到的
self_delegated_bandwidth自我抵押带宽。在delband状态表里查到的
refund_request退款请求。在refunds状态表里查到的
voter_info投票相关。在voters状态表里查到的

 

 

实例化EOS对象

const wif = '私钥'
eos = Eos({
        httpEndpoint: 'https://api.eosnewyork.io',
        chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
        keyProvider: wif,
        verbose: true
      })

RAM

  • 获取总网RAM (GB)
eos.getTableRows(true,"eosio","eosio","global",10).then(result => {
    console.log(result.rows[0].max_ram_size/(1024*1024*1024));
})
  • 获取RAM当前价格

参考(获取RAM实时价格)

  • 获取总网RAM使用量
eos.getTableRows(true,"eosio", "eosio", "rammarket").then(result => {
    var ramBaseBalance = result.rows[0].base.balance; // Amount of RAM bytes in use
    ramBaseBalance = ramBaseBalance.substr(0,ramBaseBalance.indexOf(' '));
    console.log(ramBaseBalance);
})
  • 获取总网已购买RAM的EOS总数
eos.getTableRows(true,"eosio", "eosio", "rammarket").then(result => {
    var ramQuoteBalance = result.rows[0].quote.balance; // Amount of EOS in the RAM collector
    ramQuoteBalance = ramQuoteBalance.substr(0,ramQuoteBalance.indexOf(' '));
    console.log(ramQuoteBalance);
})

 

通过get_account ,获取所有节点CPU 和 NET 信息,取平均值

NET 

  • 获取当前NET价格(EOS/KiB/Day)
eos.getAccount("eosnewyorkio").then(result => {
    var netStaked = result.total_resources.net_weight.substr(0,result.total_resources.net_weight.indexOf(' '));
    var netAvailable = result.net_limit.max / 1024; //~ convert bytes to kilobytes
    netPriceEos = ((netStaked / netAvailable)/3).toFixed(8); //~ divide by 3 to get average per day from 3 day avg
    console.log(netPriceEos);
})

CPU

  • 获取当前CPU价格(EOS/ms/Day)
eos.getAccount("eosnewyorkio").then(result => {
    var cpuStaked = result.total_resources.cpu_weight.substr(0,result.total_resources.cpu_weight.indexOf(' '));
    var cpuAvailable = result.cpu_limit.max / 1000; // convert microseconds to milliseconds
    cpuPriceEos = ((cpuStaked / cpuAvailable)/3).toFixed(8); //~ divide by 3 to get average per day from 3 day avg
    console.log(cpuPriceEos);
})

科普

什么是RAM?

RAM需要在区块链上存储数据,必须购买。 您可以根据当前的RAM市场价格获得一定数量的存储字节数。 价格会根据买卖行为自动调整。 当您释放存储空间时,您可以以当前的市场价格出售RAM以恢复EOS。

什么是网络带宽?

网络带宽的测量值是过去3天内的平均消耗量(以字节为单位)。 每次发送操作或事务时都会暂时消耗净带宽,但会随着时间的推移而减少返回0.净带宽所占用的令牌越多,您使用的越多。 您可以随时取消收回您的EOS令牌。

什么是CPU带宽?

CPU带宽测量为过去3天内的平均消耗量(以微秒为单位)。 发送操作或事务时临时消耗CPU带宽,但随着时间的推移逐渐减少,返回0.事务运行的时间越长,消耗的CPU带宽就越多。 您可以随时取消收回您的EOS令牌。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值