Skip to main content

Staking

Staking on Mintlayer works through delegations: you create a delegation ID pointing at a stake pool, stake coins to it, and withdraw rewards later. The pool itself is operated by a staker; the pool-operator workflow is covered in Staking and Delegation (SDK) (Go SDK) and in the wallet-cli staking guide.

The SDK's Client covers the delegator side. Every method also has a buildX variant that returns an unsigned transaction; see Transactions.

Creating a delegation

const signedTx = await client.delegationCreate({
pool_id: 'sp1...', // stake pool to delegate to
destination: 'tmt1q...', // address that will own the delegation
});

This registers a new delegation ID owned by destination. Staking happens against this ID (or directly against the pool ID).

Staking

const signedTx = await client.delegationStake({
pool_id: 'sp1...',
amount: 100,
});

Pass delegation_id instead of pool_id to stake through an existing delegation:

await client.delegationStake({ delegation_id: 'd1...', amount: 100 });

Querying delegations

const delegations = await client.getDelegations();
const total = await client.getDelegationsTotal();

getDelegations returns the delegations owned by the connected addresses, including their balances; getDelegationsTotal returns the sum.

Withdrawing

const signedTx = await client.delegationWithdraw({
delegation_id: 'd1...',
amount: 50,
});

As with staking, pool_id may be passed instead of delegation_id. Withdrawn coins are sent back to the owning account.

Example: stake to a pool

import { Client } from '@mintlayer/sdk';

const client = await Client.create({ network: 'testnet' });
await client.connect();

// 1. Create a delegation for the chosen pool
await client.delegationCreate({
pool_id: 'sp1...',
destination: client.getAddresses().receiving[0],
});

// 2. Stake to it
const [delegation] = await client.getDelegations();
await client.delegationStake({ delegation_id: delegation.delegation_id, amount: 100 });

// 3. Later: withdraw rewards
const total = await client.getDelegationsTotal();

For server-side automation (staking in the background without a browser), the same calls work with a standalone account provider; for the wallet-daemon equivalent see Staking with the Wallet RPC.