1

This is how to get the free balance of an account:

api.query.system.account(stash_account_address).data.free.toBigInt()

How to get the bonded balance instead?

1 Answer 1

2

To get a bunch of metadata about the a users staking configuration, you can do:

api.derive.staking.account(stash_account_address)

This returns an object like:

"{
  \"nextSessionIds\": [],
  \"sessionIds\": [],
  \"accountId\": \"..\",
  \"controllerId\": \"..\",
  \"exposure\": {
    \"total\": 0,
    \"own\": 0,
    \"others\": []
  },
  \"nominators\": [ ... ],
  \"rewardDestination\": {
    \"staked\": null
  },
  \"stakingLedger\": {
    \"stash\": \"...\",
    \"total\": 223370014049,
    \"active\": 223370014049,
    \"unlocking\": [],
    \"claimedRewards\": []
  },
  \"stashId\": \"...\",
  \"validatorPrefs\": {
    \"commission\": 0,
    \"blocked\": false
  },
  \"redeemable\": \"0x00000000000000000000000000000000\"
}"

In this case stakingLedger.total will be the total balance bonded in Staking. stakingLedger.active will be the amount actively bonded, and stakingLedger.unlocking will note whatever amounts are waiting to be unbonded.

If you want to query this stuff directly, you need to look inside the staking pallet:

api.query.staking.ledger(stash_account_address)

Where you will get just:

"{
  \"stash\": \"EGVQCe73TpFyAZx5uKfE1222XfkT3BSKozjgcqzLBnc5eYo\",
  \"total\": 1899823370014049,
  \"active\": 1899823370014049,
  \"unlocking\": [],
  \"claimedRewards\": [ ... ]
}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.