1

I am wondering how can I get the current delegation and rewards of a particular user by passing its user_id programatically in flow (mostly in typescript or python) !? I have tried it js SDK. but their isnt any support in it for staking and reward balance i guess I need help regarding this

1 Answers1

2
import LockedTokens from 0x8d0e87b65159ae63
import FlowIDTableStaking from 0x8624b52f9ddcd04a
pub fun main(address:Address) : FlowIDTableStaking.DelegatorInfo {
    let acct=getAuthAccount(address)
    let holderRef = acct.borrow<&LockedTokens.TokenHolder>(from: LockedTokens.TokenHolderStoragePath) ?? panic("TokenHolder is not saved at specified path")

    let delegatorNodeID = holderRef.getDelegatorNodeID() ?? panic("could not get delegator node id")
    let delegatorID = holderRef.getDelegatorID() ?? panic("could not get delegator id") 
    return  FlowIDTableStaking.DelegatorInfo(nodeID: delegatorNodeID, delegatorID: delegatorID)
}

This code is dervied from several scripts over here https://github.com/onflow/flow-core-contracts/tree/master/transactions

You have to call that script in any flow SDK and it should give you out the DelegatorInfo struct defined here https://github.com/onflow/flow-core-contracts/blob/3198bb0d01351daaf207e82c930da5fc0cc60fa8/contracts/FlowIDTableStaking.cdc#L379

bjartek
  • 929
  • 1
  • 5
  • 11