Stake more DOT (BONDEXTRA)

0. Initial setup

Copy
Copied
# imports
import requests

# Script parameters
ACCOUNT_ID = 4
AMOUNT_TO_BONDEXTRA = 0.1
LAM_USER = "lam_creator"
LAM_URL = "<LAM_URL>"

1. Get info about you account

GET /accounts/{ACCOUNT_ID}

Copy
Copied
account = requests.get(LAM_URL + f"/accounts/{ACCOUNT_ID}", headers={"X-Ledger-API-User": LAM_USER}).json()

Example response :

Copy
Copied
{
  "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,  // We will be taking funds from this balance
      "bonded": 2571220329540,  // Funds will go to this balance
      "fee_frozen": 2781220329540,
      "free": 2849549737776,
      "misc_frozen": 2781220329540,
      "reserved": 200410000000,
      "total": 3049959737776,
      "total_unbonded": 0,
      "total_unbonding": 210000000000,
      "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 BONDEXTRA more than you have bonded, otherwise the transaction will fail

Copy
Copied
if account["coin_fields"]["balances"]["available"] < AMOUNT_TO_BONDEXTRA:
    raise ValueError("Not enough available to BONDEXTRA")

3. Create an BONDEXTRA transaction request

POST /transactions

Copy
Copied
transaction_result = requests.post(
    LAM_URL + f"/transactions",
    json={
        "account_name": account["name"],
        "amount": {
            "unit": "DOT",
            "value": str(AMOUNT_TO_BONDEXTRA)
        },
        "coin_fields": {"type": "BONDEXTRA"},
        "max_fees": {"value": "0", "unit": "Planck"},
        "note": {
            "title": "LAM BONDEXTRA TX",
            "content": f"{AMOUNT_TO_BONDEXTRA // (10 ** 10)} DOT BONDEXTRA TX MADE THROUGH THE LAM"
        },
        "recipient": "",
        "speed": "CUSTOM",
    },
    headers={"X-Ledger-API-User": LAM_USER},
)
Copyright © Ledger Enterprise Platform 2023. All right reserved.