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_weight | cpu资源权重 |
net_limit | 网络带宽资源,包括已使用、剩余可用、总量 |
cpu_limit | cpu带宽资源,包括已使用、剩余可用、总量 |
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使用量
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令牌。