这里讲一下EOS RAM 价格的计算方法,基于eos4j项目。
直接上代码,如下:
@Test
public void getRate() {
EosRpcService eosRpcService = new EosRpcService("https://proxy.eosnode.tools");//公网超级节点
TableRowsReq tableRowsReq = new TableRowsReq();
tableRowsReq.setJson(true);
tableRowsReq.setCode("eosio");
tableRowsReq.setScope("eosio");
tableRowsReq.setTable("rammarket");
TableRows tableRows = eosRpcService.getTableRows(tableRowsReq);
int n = 1;
Map<String, String> tableRow = tableRows.getRows().get(0);
Map<String, String> quote = JSON.parseObject(JSON.toJSONString(tableRow.get("quote")), Map.class);
double quoteBalance = Double.parseDouble(quote.get("balance").split(" ")[0]);
Map<String, String> base = JSON.parseObject(JSON.toJSONString(tableRow.get("base")), Map.class);
double baseBalance = Double.parseDouble(base.get("balance").split(" ")[0]);
double ramPrice = (n * quoteBalance) / (n + baseBalance / 1024);
System.out.println(ramPrice+" EOS/KB");
}