Skip to main content

Manage Stake

The delegation from Delegate and withdraw is in place; this page manages it over its lifetime: reading status and rewards to show in a UI, unwinding the registration when a user leaves, and the combined flow that delegates stake and voting power in one transaction. The snippets reuse the same setup.

Query delegation and rewards

Read which pool a stake credential is delegated to and how many rewards have accrued, to show status in a UI, or to decide how much to withdraw.

const delegation = await client.getWalletDelegation()

console.log("Pool:", delegation.poolId) // null if not delegated
console.log("Rewards:", delegation.rewards) // lovelace

To query an arbitrary reward address instead of the wallet's, use client.getDelegation(rewardAddress). Both return { poolId, rewards }.

Deregister and reclaim the deposit

Deregistering removes the stake credential and refunds the registration deposit. Withdraw rewards first. Rewards are lost after deregistration. The best practice is to do both in the same transaction.

const delegation = await client.getWalletDelegation()

const tx = await client
.newTx()
.withdraw({ stakeCredential, amount: delegation.rewards })
.deregisterStake({ stakeCredential })
.build()

const signed = await tx.sign()
await signed.submit()

Use deregisterStakeLegacy({ stakeCredential }) if you registered with the legacy certificate.

Delegate stake and vote together

Conway-era Cardano has a second, independent delegation: governance voting power. You can delegate stake to one pool and your vote to a different DRep, and change either without affecting the other. The full DRep flow lives in DReps & vote delegation, but because both are stake-credential certificates, you can combine them in a single transaction:

import { Credential, DRep } from "@evolution-sdk/evolution"

declare const stakeCredential: Credential.Credential
declare const poolKeyHash: any
declare const drepKeyHash: any

// Register + delegate stake + delegate vote, all at once
const tx = await client
.newTx()
.registerAndDelegateTo({
stakeCredential,
poolKeyHash,
drep: DRep.fromKeyHash(drepKeyHash)
})
.build()

Already registered? Drop the registration step: Evolution delegateToPoolAndDRep({ stakeCredential, poolKeyHash, drep }), Mesh just the two delegation certificates. The DRep can also be an abstain or no-confidence option (DRep.alwaysAbstain() / DRep.alwaysNoConfidence() in Evolution).

Next steps

  • Governance: what that vote delegation feeds into, the bodies, action types, and ratification rules of on-chain governance