RE: RE: Hivejs开发实战指南
You are viewing a single comment's thread from:

RE: Hivejs开发实战指南

Words
10
Reading
1 min
Listen
Play
8M

HP代理是以VESTS来计算的

hive.broadcast.delegateVestingShares(wif, delegator, delegatee, vesting_shares, function(err, result) {
  console.log(err, result)
})
wif - 
delegator - 
delegatee - 
vesting_shares - hpvests 

//VESTS和HP换算关系
async function main() {
  let s = await hive.api.getDynamicGlobalPropertiesAsync()
  console.log(11, s)
  console.log(12, s.total_vesting_shares)
  console.log(13, s.total_vesting_fund_hive)
  console.log(14, "hp_to_vests", parseFloat(s.total_vesting_shares) / parseFloat(s.total_vesting_fund_hive))
}
main()
//
12 313254970159.720284 VESTS
13 188674228.477 HIVE
 1 HP = 1660.295487 VESTS

eg:
async delegate(){
  let wif = '5KNxxxxxxxxxxxxxxx'
  let delegator = 'lemool'
  let delegatee = "lucky"
  let a = await hive.api.getDynamicGlobalPropertiesAsync()
  let hp_to_vests = parseFloat(a.total_vesting_shares) / parseFloat(a.total_vesting_fund_hive)
  let b = '1.8' * hp_to_vests  //代理1.8个HP
  let c = b.toFixed(6)  //6位小数
  let vests = c+' VESTS'  //换算成VESTS
  await hive.broadcast.delegateVestingSharesAsync(wif, delegator, delegatee, vests)
}
////执行结果:
operations: Array(1)
0: Array(2)
0: "delegate_vesting_shares"
1:
delegatee: "lucky"
delegator: "lemool"
vesting_shares: "3483.359523 VESTS"
__proto__: Object
length: 2

: 1HP,07