DOT

SDK functions for DOT staking on Polkadot protocol

Introduction to Polkadot staking

As a staker, there are two ways to stake your assets on Polkadot.

You can either join a nomination pool or nominate your validators manually.

Nomination pools allow users to pool their DOT tokens together on-chain to nominate validators and receive rewards. Participating in pools is more of a set-and-forget action than nominating by yourself. The pool operator maintains the list of validators nominated by the pool, and so, in a way, you are trusting the pool operator to act in your best interests. You can join a nomination pool with a minimum of 1 DOT.

Nominating manually

Nominating is the action of choosing validators. It does not simply involve bonding tokens. Nominating is an active task, which implies that you regularly monitor that your stake is backing an active validator in all the eras and check if you are receiving your staking rewards. More importantly, ensure that the validators you chose always act in the best interests of the network protocol and have less chance of getting slashed. To nominate, you need a minimum of 250 DOT, and to receive rewards, you need at least a balance greater than the minimum active bond.

Learn more.

Nomination pool functions

Join a pool

Join a nomination pool.

The amount to bond is in DOT.

You can find the pool id that you want to join in the URL of the pool, eg Kiln's pool id is 118:

https://polkadot.subscan.io/nomination_pool/118

const tx = await k.dot.craftJoinPoolTx('kiln_account_id', 'member_account', 1, '118');

Bond extra to pool

A bond extra to pool transaction allows you to bond more tokens from your balance to the pool.

The amount to bond is in DOT.

const tx = await k.dot.craftBondExtraToPoolTx('member_account', 1);

Bond rewards to pool

A bond rewards to pool transaction allows you to bond your available rewards to the pool. You can use this feature to compound your rewards automatically.

const tx = await k.dot.craftBondRewardsToPoolTx('member_account');

Claim payout from pool

A claim payout from pool transaction transfers your available rewards to your wallet.

const tx = await k.dot.craftClaimPayoutFromPoolTx('member_account');

Unbond from pool

An ubond from pool transaction allows you unbond tokens from the pool. Your tokens remains locked for 28 days before you can withdraw them.

The amount to unbond is in DOT.

Warning

You cannot rebond during the unbonding period with a nomination pool. If you change your mind, you must wait for the unbonding period to end before you can join a nomination pool again.
const tx = await k.dot.craftUnbondFromPoolTx('member_account', 1);

Withdraw unbonded from pool

A withdraw unbonded from pool transaction allows you to withdraw unbonded tokens from the pool.

const tx = await k.dot.craftWithdrawUnbondedFromPoolTx('member_account');

Nominating directly functions

Bond

A bond transaction allows you to lock tokens that will be used by your nominated validators. The bond transaction should be made if this is the first time you bond tokens from your wallet. If you already have some tokens bonded, use the craftBondExtraTx function.

The account_id is used to link your DOT stake to your Kiln account.

The stash account is the wallet from which you are bonding token.

The amount to bond is in DOT.

The reward destination can be set to:

  • Staked: rewards are paid into the stash account, increasing the amount at stake accordingly (auto-compounding).

  • Stash: rewards are paid into the stash account, not increasing the amount at stake (not auto-compounding).

  • Custom account address: rewards are paid into the custom account address (not auto-compounding)

const tx = await k.dot.craftBondTx('account_id', 'stash_account', 1, 'reward_destination');

Bond extra

A bond extra transaction allows you to lock more tokens to already bonded tokens.

The amount to bond is in DOT.

const tx = await k.dot.craftBondExtraTx('stash_account', 1);

Rebond

A rebond transaction allows you to bond back tokens that are currently unbonding.

The amount to rebond is in DOT.

const tx = await k.dot.craftRebondTx('controller_account', 1);

Nominate

A nominate transaction allows you to nominate validators (up to 16). Once done, if your nominated validators are elected to produce block on the current era, you will start earning rewards.

const tx = await k.dot.craftNominateTx('controller_account', ['validator_address_1', 'validator_address_2']);

Unbond

An unbond transaction allows you to unlock bonded tokens. The unbonding period is about 28 days.

The amount to unbond is in DOT.

const tx = await k.dot.craftUnbondTx('controller_account', 1);

Withdraw unbonded

A withdraw unbonded transaction allows you to withdraw unbonded tokens so all unbonded tokens become available in your wallet.

const tx = await k.dot.craftWithdrawUnbondedTx('controller_account');

Chill

A chill transaction allows you to freeze a controller account. This means that the controller account will stop nominate validators and you will stop earning rewards from the next era.

const tx = await k.dot.craftChillTx('controller_account');

Set payee

A set payee transaction allows you to update the reward destination address for the given controller account. You can use the following destination options:

  • Staked: rewards are paid into the stash account, increasing the amount at stake accordingly (auto-compounding).

  • Stash: rewards are paid into the stash account, not increasing the amount at stake (not auto-compounding).

  • Controller: rewards are paid into the controller account (not auto-compounding)

  • Custom account address: rewards are paid into the custom account address (not auto-compounding)

const tx = await k.dot.craftSetPayeeTx('controller_account', 'Staked');

Sign

Sign a transaction by specifying the integration and the crafted transaction.

Here is an example showing how to sign a transaction with a fireblocks vault.

Checkout the setup fireblocks documentation to setup your vault.

import { Integration } from "@kilnfi/sdk/lib/types/integrations";
const fs = require('fs');
const apiSecret = fs.readFileSync(__dirname + '/fireblocks_secret.key', 'utf8');

const vault: Integration = {
      provider: 'fireblocks',
      fireblocksApiKey: 'YOUR_API_USER_KEY', // your fireblocks API user key
      fireblocksSecretKey: apiSecret, // your fireblocks private key (generated with your CSR file and your API user)
      vaultId: 7 // your fireblocks vault id
};
const txSigned = await k.dot.sign(vault, tx);

Broadcast

Broadcast a signed transaction.

const txHash = await k.dot.broadcast(txSigned);

Get transaction status

Get the transaction status of a broadcasted transaction by providing its transaction hash.

const status = await k.dot.getTxStatus('tx_hash');

Decode transaction

Decode a serialized transaction previously crafted. You can use this to get more information about a transaction prior to broadcast it such as the gas fees used, the function parameters etc.

const decodedTx = await k.dot.decodeTx('tx_serialized');

Last updated