# How to un-delegate and get key deposit back?

**URL:** <https://forum.cardano.org/t/how-to-un-delegate-and-get-key-deposit-back/54613>\
**Category:** General Discussions\
**Created:** [22 March 2021 04:37 UTC](https://forum.cardano.org/t/how-to-un-delegate-and-get-key-deposit-back/54613 "2021-03-22T04:37:39Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Jun\_Sun](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/jun_sun/32/30663_2.png) [@Jun\_Sun](https://forum.cardano.org/u/Jun_Sun)\
**Post date:** [24 March 2021 03:36 UTC](https://forum.cardano.org/t/how-to-un-delegate-and-get-key-deposit-back/54613/4 "2021-03-24T03:36:31Z")

</div>

I found the answer myself. The key is to call “cardano-cli stake-address deregistration-certificate”. Below is the full commandline.

```
cardano-cli stake-address deregistration-certificate \
    --stake-verification-key-file stake.vkey \
    --out-file stake.cert

```

And then build a transaction with this certificate. Specifically you need to increase the change amount by 2 ADA and minus the transaction.

```
txOut=$((${total_balance}+${keyDeposit}-${fee}))
cardano-cli transaction build-raw \
    ${tx_in} \
    --tx-out $(cat payment.addr)+${txOut} \
    --invalid-hereafter $(( ${currentSlot} + 10000)) \
    --fee ${fee} \
    --certificate-file stake.cert \
    --mary-era \
    --out-file /tmp/tx.raw
```

---

_[View the full topic](https://forum.cardano.org/t/how-to-un-delegate-and-get-key-deposit-back/54613)._
