Un-Stake DOT (UNBOND)
0. Initial setup
# imports
import requests
# Script parameters
ACCOUNT_ID = 4
AMOUNT_TO_UNBOND = 0.1 # DOT
LAM_USER = "lam_creator"
LAM_URL = "<LAM_URL>"
1. Get info about you account
GET /accounts/{ACCOUNT_ID}
account = requests.get(LAM_URL + f"/accounts/{ACCOUNT_ID}", headers={"X-Ledger-API-User": LAM_USER}).json()
Example response :
{
"address": "12MJp8QmUPMM78nQwkS6g9pq7oEX45tXyBdHHAhh762xyXJ5",
"available_balance": "58329408236",
"balance": "3049959737776",
"coin_fields": {
"anonymous_proxy": {
"address": "16AL3CZ1UeBHj4nbvxnNJTQufAaGtyEXtHgCuUcF1quEW9hx",
"balances": {
"available": 9670000000,
"bonded": 0,
"fee_frozen": 0,
"free": 19670000000,
"misc_frozen": 0,
"reserved": 330000000,
"total": 20000000000
},
"block_height": 10737260,
"created_at": "2022-06-14T09:00:24+00:00",
"ext_index": 2,
"index": 0,
"is_controller": true,
"is_main": true,
"kind": "Any"
},
"balances": {
"available": 58329408236,
"bonded": 2571220329540, // funds will be taken from this balance
"fee_frozen": 2781220329540,
"free": 2849549737776,
"misc_frozen": 2781220329540,
"reserved": 200410000000,
"total": 3049959737776,
"total_unbonded": 0, // funds will go to this balance...
"total_unbonding": 210000000000, // ... and will automatically end up here after 28 days
"unbonded": [],
"unbonding": [
{
"amount": 209000000000,
"waiting_time": 431590
},
{
"amount": 1000000000,
"waiting_time": 2159590
}
]
},
"staking": {
"controller_address": "16AL3CZ1UeBHj4nbvxnNJTQufAaGtyEXtHgCuUcF1quEW9hx",
"proxies": [
"12TzkPCrVfrZxupsdkt3vxZQS7Ajw3DVcpFpBH2PBDU4Uyja"
],
"rewards_destination": "Staked"
},
"type": "Polkadot"
},
"currency": "polkadot",
"id": 4,
"name": "Polkadot 0",
"type": "Polkadot",
[...]
}
2. Make sure you don't try to unbond more than you have bonded, otherwise the transaction will fail
if account["coin_fields"]["balances"]["bonded"] < AMOUNT_TO_UNBOND:
raise ValueError("Not enough bonded to unbond")
3. Create an UNBOND transaction request
POST /transactions
transaction_result = requests.post(
LAM_URL + f"/transactions",
json={
"account_name": account["name"],
"amount": {
"unit": "DOT",
"value": str(AMOUNT_TO_UNBOND)
},
"coin_fields": {"type": "UNBOND"},
"max_fees": {"value": "0", "unit": "Planck"},
"note": {
"title": "LAM UNBOND TX",
"content": f"{AMOUNT_TO_UNBOND // (10 ** 10)} DOT UNBOND TX MADE THROUGH THE LAM"
},
"recipient": "",
"speed": "CUSTOM",
},
headers={"X-Ledger-API-User": LAM_USER},
)