> ## Documentation Index
> Fetch the complete documentation index at: https://pond.dflow.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Reclaim Rent

> How to close empty outcome token accounts to reclaim rent

<Info>
  On Solana, accounts must hold a rent-exempt balance (lamports) to exist. When you close an empty token account, those lamports are returned to the destination you specify. If you set [`outcomeAccountRentRecipient`](/resources/trading-api/order/order#parameter-outcome-account-rent-recipient) when requesting an order, retrieve that value from your stored order params and reuse it as the close destination. Otherwise, choose any destination (typically the user's wallet).

  Closing a token account is a standard SPL Token action. DFlow does not provide a dedicated endpoint for this.
</Info>

<Steps>
  <Step title="Choose the rent destination">
    Decide where the reclaimed rent should go. If your app set
    [`outcomeAccountRentRecipient`](/resources/trading-api/order/order#parameter-outcome-account-rent-recipient) when creating the order, use that address.

    <AccordionGroup>
      <Accordion title="Select a rent destination">
        ```typescript theme={null}
        import "dotenv/config";

        import {
          createBurnInstruction,
          createCloseAccountInstruction,
          getAccount,
        } from "@solana/spl-token";
        import { Connection, Keypair, PublicKey, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
        import bs58 from "bs58";

        const SOLANA_RPC_URL = process.env.SOLANA_RPC_URL ?? "https://api.mainnet-beta.solana.com";

        const keypair = Keypair.fromSecretKey(
          bs58.decode(process.env.SOLANA_PRIVATE_KEY ?? "")
        );

        const userPublicKey = keypair.publicKey.toBase58();

        // Optional: reuse the address you set when creating the order.
        // If you did not set one, default to the user's wallet.
        const outcomeAccountRentRecipient =
          storedOrderParams?.outcomeAccountRentRecipient ?? null;

        const rentDestination = outcomeAccountRentRecipient ?? userPublicKey;
        ```
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="Burn remaining tokens and close the account">
    A token account must be empty to close. If it still has a balance, burn the
    remaining outcome tokens and then close the account to reclaim rent.

    <AccordionGroup>
      <Accordion title="Burn and close an outcome token account">
        ```typescript theme={null}
        const connection = new Connection(SOLANA_RPC_URL, "confirmed");
        const owner = keypair; // signer and token account owner

        const tokenAccount = new PublicKey("OUTCOME_TOKEN_ACCOUNT");
        const outcomeMint = new PublicKey("OUTCOME_TOKEN_MINT");
        const rentRecipient = new PublicKey(rentDestination);

        const account = await getAccount(connection, tokenAccount);

        const instructions = [];
        if (account.amount > 0n) {
          instructions.push(
            createBurnInstruction(
              tokenAccount,
              outcomeMint,
              owner.publicKey,
              account.amount
            )
          );
        }

        instructions.push(
          createCloseAccountInstruction(
            tokenAccount,
            rentRecipient,
            owner.publicKey
          )
        );

        const tx = new Transaction().add(...instructions);
        const signature = await sendAndConfirmTransaction(connection, tx, [owner]);
        console.log(`  Tx: https://orbmarkets.io/tx/${signature}`);
        ```
      </Accordion>
    </AccordionGroup>
  </Step>
</Steps>

## Related Resources

<CardGroup cols={2}>
  <Card title="Redeem Outcome Tokens" href="/prediction-markets/recipes/redeem-outcome-tokens" icon="check-circle">
    Redeem winning outcome tokens once a market is determined.
  </Card>

  <Card title="Track User Positions" href="/prediction-markets/recipes/track-positions" icon="chart-line">
    Map wallet balances back to markets and outcomes.
  </Card>
</CardGroup>

## API Routes

This recipe does not call DFlow APIs. It uses a Solana RPC endpoint and the SPL
Token program.
