区块链中文技术社区

获取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

参考:github

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »