> ## 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.

# Check Borrower Loan Eligibility with the BlackSwan SDK

> Learn how to check if a wallet qualifies for a loan using the BlackSwan SDK, including tier checks, APR calculation, and default history.

Before offering a loan, you need to know whether a borrower meets your platform's minimum credit requirements. BlackSwan provides trust tier, credit history, and current APR data so you can make that determination programmatically.

## Prerequisites

Install the BlackSwan JavaScript SDK:

```bash theme={null}
npm install blackswan-sdk
```

## Client Setup

```ts theme={null}
import { BlackSwanClient } from "blackswan-sdk";

const client = new BlackSwanClient({
  network: "amoy",
  rpcUrl: process.env.NEXT_PUBLIC_RPC_URL!
});
```

## Simple Eligibility Check

The function below compares the borrower's tier against your minimum required tier and ensures they have no defaults on record:

```ts theme={null}
import { BlackSwanClient } from "blackswan-sdk";

const client = new BlackSwanClient({
  network: "amoy",
  rpcUrl: process.env.NEXT_PUBLIC_RPC_URL!
});

async function checkEligibility(wallet: string, minTier: string): Promise<boolean> {
  const [tier, history] = await Promise.all([
    client.getTrustTier(wallet),
    client.getCreditHistory(wallet)
  ]);

  const tierRank: Record<string, number> = { A: 5, B: 4, C: 3, D: 2, E: 1 };

  return tierRank[tier] >= tierRank[minTier] && history.defaults === 0;
}
```

## Advanced Risk Profile

For a richer picture, pull the full credit dashboard alongside the borrower's current APR and history in a single parallel request:

```ts theme={null}
async function getBorrowerRisk(wallet: string) {
  const [dashboard, history, apr] = await Promise.all([
    client.getCreditDashboard(wallet),
    client.getCreditHistory(wallet),
    client.getCurrentApr(wallet)
  ]);

  // APR is returned in basis points — divide by 1000 to get a percentage.
  // For example, a raw value of 142 = 0.142%.
  return {
    tier: dashboard.trustTierScore,
    apr: apr / 1000,
    defaults: history.defaults,
    successRate: (history.successfulLoans / (history.totalLoans || 1)) * 100
  };
}
```

## Putting It Together

Here is a complete example that checks eligibility and, if approved, retrieves the full risk profile:

```ts theme={null}
import { BlackSwanClient } from "blackswan-sdk";

const client = new BlackSwanClient({
  network: "amoy",
  rpcUrl: process.env.NEXT_PUBLIC_RPC_URL!
});

async function evaluateBorrower(wallet: string) {
  const eligible = await checkEligibility(wallet, "B");

  if (!eligible) {
    console.log("Borrower does not meet minimum eligibility requirements.");
    return;
  }

  const risk = await getBorrowerRisk(wallet);
  console.log(`Approved — Tier: ${risk.tier}, APR: ${risk.apr.toFixed(3)}%, Success rate: ${risk.successRate.toFixed(1)}%`);
}

evaluateBorrower("0xYourWalletAddress");
```
