EOS 获取RAM实时价格

命令如下

cleos -u https://nodes.get-scatter.com:443 get table eosio eosio rammarket

获取的结果为

{
  "rows": [{
      "supply": "10000000000.0000 RAMCORE",
      "base": {
        "balance": "12341975994 RAM",
        "weight": "0.50000000000000000"
      },
      "quote": {
        "balance": "5568015.6361 EOS",
        "weight": "0.50000000000000000"
      }
    }
  ],
  "more": false
}

然后使用Bancor算法,计算出需要nKB的RAM的价格

RAM价格 = (n * quote.balance) / (n + base.balance / 1024)

RPC代码实现如下

const wif = '5JC9FdRjX3c3fsB62S5Tz22LgTuRHegb1XEV16uft8u3njmm9E5'
eos = Eos({
    httpEndpoint: 'https://nodes.get-scatter.com:443',
    chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
    keyProvider: wif,
    verbose: true
    })
eos.getTableRows(true,"eosio", "eosio", "rammarket").then(result => {
    console.log(1 * result.rows[0].quote.balance.split(" ")[0] / (1 + result.rows[0].base.balance.split(" ")[0] / 1024));
}).catch(e => {
    console.error(e);
})

当前返回价格:0.4716754832469308 EOS/Kib

 

版权属于:Surou

本文链接:https://www.bcskill.com/index.php/archives/255.html

欢迎添加区块连技术QQ群:791420381 ------ 转载或参考已注明,互相尊重知识版权。转载时须征得本人同意并注明出处及本声明

你可能感兴趣的:(区块链)