api.client.Staking - PolymeshAssociation/polymesh-sdk GitHub Wiki
@polymeshassociation/polymesh-sdk / api/client/Staking
api/client/Staking
Classes
Staking
Defined in: api/client/Staking.ts:214
Handles Staking related functionality
Methods
bond()
bond(
args,opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:297
Bond POLYX for staking
Parameters
| Parameter | Type |
|---|---|
args |
BondPolyxParams |
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
the signing Account cannot already be a stash — use bondExtra to add to a bond it already has — nor a controller for another stash, since one Account cannot be both
Note
this method is of type ProcedureMethod, which means you can call bond.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it
bondExtra()
bondExtra(
args,opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:304
Bond extra POLYX for staking
Parameters
| Parameter | Type |
|---|---|
args |
UpdatePolyxBondParams |
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
this transaction must be signed by a stash
Note
this method is of type ProcedureMethod, which means you can call bondExtra.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it
chill()
chill(
opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:331
Stop nominating validators, without unbonding any POLYX
Parameters
| Parameter | Type |
|---|---|
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
the bonded POLYX stays bonded. Use unbond to begin withdrawing it
Note
this transaction must be signed by a controller
Note
this method is of type NoArgsProcedureMethod, which means you can call chill.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it
eraInfo()
Call Signature
eraInfo():
Promise<StakingEraInfo>
Defined in: api/client/Staking.ts:465
Retrieve information about the staking eras the chain is tracking
Returns
Promise<StakingEraInfo>
Promise that resolves to the era information
Note
the chain tracks two era numbers and they are not interchangeable. currentEra is
the latest era the chain has planned — a validator set has been elected for it, but the
Session pallet may not have brought it into force. activeEra is the era whose validator set
is in force and whose rewards and slashes are being processed. currentEra runs ahead of
activeEra between an election and the session rotation that follows it, and the two are
equal the rest of the time. Anything describing what the chain is doing now wants activeEra
Call Signature
eraInfo(
callback):Promise<UnsubCallback>
Defined in: api/client/Staking.ts:476
Retrieve the current staking era information (with subscription support)
Parameters
| Parameter | Type | Description |
|---|---|---|
callback |
SubCallback<StakingEraInfo> |
Callback function that receives era information updates |
Returns
Promise<UnsubCallback>
Promise that resolves to an unsubscribe function
Note
can be subscribed to, if connected to node using a web socket
eraProgress()
Call Signature
eraProgress():
Promise<EraProgress>
Defined in: api/client/Staking.ts:637
Retrieve how far through the staking cycle the chain is — which era and session are in force, and how far through each of them the chain has got
Returns
Promise<EraProgress>
Throws
if there is no active era
Note
progress is counted in slots, which is how the chain measures a period, so
progress is exact. The remaining and end projections come from expectedBlockTime and
move as block production drifts
Call Signature
eraProgress(
callback):Promise<UnsubCallback>
Defined in: api/client/Staking.ts:649
Retrieve how far through the staking cycle the chain is, and subscribe to its advance
Parameters
| Parameter | Type | Description |
|---|---|---|
callback |
SubCallback<EraProgress> |
called on every block, since the slot the progress is counted in advances with each one. This is what drives a progress bar without polling |
Returns
Promise<UnsubCallback>
Promise that resolves to an unsubscribe function
Note
can be subscribed to, if connected to node using a web socket
getActiveValidators()
getActiveValidators():
Promise<Account[]>
Defined in: api/client/Staking.ts:421
Retrieve the validators whose set is actually in force for the active era
Returns
Promise<Account[]>
the elected validators, in the chain's own order
Note
this is a different question from
getValidators, which lists every Account
declaring intent to validate. Those declaring intent but not elected are the waiting set —
subtract this result from getValidators to get it
Note
bounded by getValidatorCount, so unlike the intent list this needs no pagination
getConstants()
getConstants():
StakingConstants
Defined in: api/client/Staking.ts:597
Retrieve the chain constants that govern staking
Returns
Note
these come from the chain's metadata, so this makes no query
getElectionPhase()
Call Signature
getElectionPhase():
Promise<ElectionPhase>
Defined in: api/client/Staking.ts:1086
Retrieve the current phase of the validator election
Returns
Promise<ElectionPhase>
Note
staking transactions behave differently while an election is open, so a UI should say
when the phase is anything other than Off
Call Signature
getElectionPhase(
callback):Promise<UnsubCallback>
Defined in: api/client/Staking.ts:1099
Retrieve the current phase of the validator election, and subscribe to it
Parameters
| Parameter | Type | Description |
|---|---|---|
callback |
SubCallback<ElectionPhase> |
called whenever the phase changes, which happens several times an era |
Returns
Promise<UnsubCallback>
Promise that resolves to an unsubscribe function
Note
this is the read that most benefits from a subscription — a warning that only appears on the next poll appears after the user has already acted
Note
can be subscribed to, if connected to node using a web socket
getElectionSchedule()
Call Signature
getElectionSchedule():
Promise<ElectionSchedule>
Defined in: api/client/Staking.ts:988
Retrieve when the next validator election opens and closes
Returns
Promise<ElectionSchedule>
Throws
if there is no active era
Note
this is the figure that says whether a nomination made now takes effect this era or the next. It is not the era's own countdown: the election closes a session before the era ends, so it can be minutes away while the era still has hours left
Call Signature
getElectionSchedule(
callback):Promise<UnsubCallback>
Defined in: api/client/Staking.ts:999
Retrieve when the next validator election opens and closes, and subscribe to it
Parameters
| Parameter | Type | Description |
|---|---|---|
callback |
SubCallback<ElectionSchedule> |
called on every block, since the projections advance with each one |
Returns
Promise<UnsubCallback>
Promise that resolves to an unsubscribe function
Note
can be subscribed to, if connected to node using a web socket
getEraExposure()
getEraExposure(
args):Promise<EraExposure|null>
Defined in: api/client/Staking.ts:899
Retrieve how much POLYX was backing a validator in an era, and how it was split
Parameters
| Parameter | Type | Description |
|---|---|---|
args |
{ era?: BigNumber; validator: string | Account; } |
- |
args.era? |
BigNumber |
defaults to the active era |
args.validator |
string | Account |
the validator's Account or address |
Returns
Promise<EraExposure | null>
null if the Account was not in the era's validator set
getEraNominators()
getEraNominators(
args):Promise<EraNominators|null>
Defined in: api/client/Staking.ts:944
Retrieve one page of the nominators backing a validator in an era
Parameters
| Parameter | Type | Description |
|---|---|---|
args |
{ era?: BigNumber; page?: BigNumber; validator: string | Account; } |
- |
args.era? |
BigNumber |
defaults to the active era |
args.page? |
BigNumber |
defaults to the first page. Read pageCount from getEraExposure for how many there are |
args.validator |
string | Account |
the validator's Account or address |
Returns
Promise<EraNominators | null>
null if the page does not exist
Note
nominators are paged by the chain so that a payout fits in a block, which is why this is not returned as part of the exposure
getEraRewardPoints()
Call Signature
getEraRewardPoints(
era?):Promise<EraRewardPoints>
Defined in: api/client/Staking.ts:777
Retrieve the reward points earned by each validator in an era
Parameters
| Parameter | Type | Description |
|---|---|---|
era? |
BigNumber |
defaults to the active era |
Returns
Promise<EraRewardPoints>
Note
points are how the era's reward is split between validators. A validator that authored no blocks in the era is absent rather than present with zero
Call Signature
getEraRewardPoints(
callback):Promise<UnsubCallback>
Defined in: api/client/Staking.ts:791
Retrieve the reward points earned by each validator in an era, and subscribe to them
Parameters
| Parameter | Type | Description |
|---|---|---|
callback |
SubCallback<EraRewardPoints> |
called as points are credited. Points accrue block by block as validators author, so for the active era this is a live leaderboard |
Returns
Promise<UnsubCallback>
Promise that resolves to an unsubscribe function
Note
only the active era changes. Subscribing to a past era is allowed and simply calls back once, since the chain has finished writing it
Note
can be subscribed to, if connected to node using a web socket
Call Signature
getEraRewardPoints(
era,callback):Promise<UnsubCallback>
Defined in: api/client/Staking.ts:800
Retrieve the reward points earned by each validator in a specific era, and subscribe to them
Parameters
| Parameter | Type |
|---|---|
era |
BigNumber |
callback |
SubCallback<EraRewardPoints> |
Returns
Promise<UnsubCallback>
Promise that resolves to an unsubscribe function
Note
can be subscribed to, if connected to node using a web socket
getEraStartSession()
getEraStartSession(
era?):Promise<BigNumber|null>
Defined in: api/client/Staking.ts:876
Retrieve the session an era started at
Parameters
| Parameter | Type | Description |
|---|---|---|
era? |
BigNumber |
defaults to the active era |
Returns
Promise<BigNumber | null>
null for an era outside the chain's history depth
getEraValidatorReward()
getEraValidatorReward(
era?):Promise<BigNumber|null>
Defined in: api/client/Staking.ts:854
Retrieve the total POLYX paid out to validators and their nominators for an era
Parameters
| Parameter | Type | Description |
|---|---|---|
era? |
BigNumber |
defaults to the active era |
Returns
Promise<BigNumber | null>
null for an era the chain has not paid out, i.e. one still running or older than the
history depth
getValidatorCount()
getValidatorCount():
Promise<BigNumber>
Defined in: api/client/Staking.ts:443
Retrieve how many validators the chain aims to elect each era
Returns
Promise<BigNumber>
Note
this is the target the election is run against, not how many are currently in force — read getActiveValidators for that. The two differ when fewer Accounts declare intent than there are slots
getValidators()
getValidators(
paginationOpts?):Promise<ResultSet<StakingCommission>>
Defined in: api/client/Staking.ts:366
Return information about nomination targets
Parameters
| Parameter | Type |
|---|---|
paginationOpts? |
PaginationOptions |
Returns
Promise<ResultSet<StakingCommission>>
Note
supports pagination
nominate()
nominate(
args,opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:345
Nominate validators for the bonded POLYX
Parameters
| Parameter | Type |
|---|---|
args |
NominateValidatorsParams |
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
this transaction must be signed by a controller
Note
this method is of type ProcedureMethod, which means you can call nominate.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it
rebond()
rebond(
args,opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:323
Rebond POLYX that is currently unbonding, without waiting for the lockup period to elapse
Parameters
| Parameter | Type |
|---|---|
args |
UpdatePolyxBondParams |
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
this transaction must be signed by a controller
Note
the chain takes the amount from the most recently unbonded POLYX first, so a partial rebond leaves the lots closest to maturing where they are
Note
this method is of type ProcedureMethod, which means you can call rebond.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it
setController()
setController(
opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:352
Allow for a stash account to update its controller so the stash becomes its own controller
Parameters
| Parameter | Type |
|---|---|
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
the transaction must be signed by a stash account
Note
this method is of type NoArgsProcedureMethod, which means you can call setController.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it
setPayee()
setPayee(
args,opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:359
Allow for a stash account to update where it's staking rewards are deposited
Parameters
| Parameter | Type |
|---|---|
args |
SetStakingPayeeParams |
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
the transaction must be signed by a controller account
Note
this method is of type ProcedureMethod, which means you can call setPayee.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it
unbond()
unbond(
args,opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:313
Unbond POLYX for staking. The unbonded amount can be withdrawn after the lockup period
Parameters
| Parameter | Type |
|---|---|
args |
UpdatePolyxBondParams |
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
the chain chills a stash that unbonds its whole ledger. Since this refuses an amount larger than the active bond, that is the case where nothing is already unlocking and the whole of it is unbonded — the stash stops nominating or validating as well
Note
this method is of type ProcedureMethod, which means you can call unbond.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it
withdraw()
withdraw(
opts?):Promise<GenericPolymeshTransaction<void,void>>
Defined in: api/client/Staking.ts:338
Withdraw unbonded POLYX to free it for the stash account
Parameters
| Parameter | Type |
|---|---|
opts? |
ProcedureOpts |
Returns
Promise<GenericPolymeshTransaction<void, void>>
Note
this transaction must be signed by a controller
Note
this method is of type NoArgsProcedureMethod, which means you can call withdraw.checkAuthorization on it to see whether the signing Account and Identity have the required roles and permissions to run it