Staking
This section covers the operations for staking your wallet on the Cardano network.
Register stake key
When registering a stake key with the Cardano network, a deposit of 2 ADA is required. This deposit acts as a pledge and is temporarily deducted from the wallet balance.
const tx = await lucid.newTx().registerStake(rewardAddress).complete();For script stake credentials that require a certificate witness, attach the certificate validator and pass the registration redeemer:
const tx = await lucid
.newTx()
.attach.CertificateValidator(certificateValidator)
.register.Stake(scriptRewardAddress, Data.void())
.complete();Omitting the redeemer uses the witnessless stake-registration certificate. Passing a redeemer uses the witnessed registration certificate and attaches the matching certificate validator.
Query the reward address (stake_...) of the selected wallet:
const rewardAddress = await lucid.wallet().rewardAddress();Delegate to a stake pool
Delegating to a stake pool involves associating your stake key with a pool identified by its unique ID.
const tx = await lucid
.newTx()
.delegateTo(rewardAddress, "poolabc...")
.complete();You can combine both registration and delegation into a single transaction:
const tx = await lucid
.newTx()
.registerAndDelegate.ToPool(rewardAddress, "poolabc...")
.complete();Withdraw rewards
Allows the wallet holder to claim any rewards accumulated through staking. The rewards are withdrawn to the wallets balance.
const delegation = await lucid.wallet().getDelegation();
const tx = await lucid
.newTx()
.withdraw(rewardAddress, delegation.rewards)
.complete();With updates to on-chain governance model of Cardano, staking rewards are only withdrawable if your wallet is delegated to a DRep (Delegated Representative). For more information about DReps and governance delegation, see the Governance documentation.