HP代理是以VESTS来计算的
hive.broadcast.delegateVestingShares(wif, delegator, delegatee, vesting_shares, function(err, result) {
console.log(err, result)
})
wif - 资金私钥
delegator - 代理人
delegatee - 被代理人
vesting_shares - hp要转换成vests
//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,要取消代理直接把代理量设为0即可,取消代理要有7天才能回到原有帐户。
RE: Hivejs开发实战指南