> ## Documentation Index
> Fetch the complete documentation index at: https://blackswan-23965643.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Loan History: Complete Borrowing Record for Any Wallet

> BlackSwan tracks total loans, successful repayments, and defaults for every wallet. Query loan history to assess borrower risk before lending.

BlackSwan maintains a complete, immutable borrowing record for every wallet that has interacted with the protocol. This loan history is publicly queryable on-chain and through the BlackSwan API, giving lenders and protocols the data they need to make informed credit decisions without relying on centralized intermediaries.

## What Is Tracked

Every time a wallet borrows through BlackSwan, the following metrics are updated:

| Field              | Type    | Description                                            |
| ------------------ | ------- | ------------------------------------------------------ |
| `totalLoans`       | integer | Total number of loans ever taken by the wallet         |
| `successfulLoans`  | integer | Number of loans fully repaid on or before the deadline |
| `defaults`         | integer | Number of loans not repaid by the deadline             |
| `totalBorrowedUsd` | number  | Cumulative USD value of all loans taken                |
| `totalRepaidUsd`   | number  | Cumulative USD value of all loans successfully repaid  |

## Querying Loan History

You can retrieve the full loan history for any wallet using the BlackSwan SDK or REST API.

<CodeGroup>
  ```javascript JavaScript theme={null}
  import { BlackSwanClient } from "blackswan-sdk";

  const client = new BlackSwanClient({ apiKey: "YOUR_API_KEY" });

  const history = await client.getCreditHistory("0xYourWalletAddress");

  console.log("Total Loans:", history.totalLoans);
  console.log("Successful Repayments:", history.successfulLoans);
  console.log("Defaults:", history.defaults);
  console.log("Total Borrowed (USD):", history.totalBorrowedUsd);
  console.log("Total Repaid (USD):", history.totalRepaidUsd);
  ```

  ```python Python theme={null}
  from blackswan import BlackSwanClient

  client = BlackSwanClient(api_key="YOUR_API_KEY")

  history = client.get_credit_history("0xYourWalletAddress")

  print("Total Loans:", history["totalLoans"])
  print("Successful Repayments:", history["successfulLoans"])
  print("Defaults:", history["defaults"])
  print("Total Borrowed (USD):", history["totalBorrowedUsd"])
  print("Total Repaid (USD):", history["totalRepaidUsd"])
  ```

  ```bash REST theme={null}
  curl -X GET "https://api.blackswan.finance/v1/history/0xYourWalletAddress" \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```
</CodeGroup>

**Example response:**

```json theme={null}
{
  "wallet": "0xYourWalletAddress",
  "totalLoans": 5,
  "successfulLoans": 4,
  "defaults": 1,
  "totalBorrowedUsd": 12000.00,
  "totalRepaidUsd": 9500.00
}
```

## Use Cases

Loan history data is useful in a variety of contexts across the lending ecosystem:

* **Lenders verifying borrowers** — Before extending credit, a lender can query a wallet's loan history to check repayment reliability and default count, making a data-driven decision on whether to approve a loan.
* **Displaying a credit profile** — Applications can surface a wallet's borrowing track record directly in their UI, giving users transparency into their own on-chain reputation.
* **Risk modeling** — Protocols and analytics tools can use `totalBorrowedUsd`, `totalRepaidUsd`, and default rates to model portfolio risk, set dynamic collateral requirements, or fine-tune APR calculations.
