> For the complete documentation index, see [llms.txt](https://docs.nomial.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nomial.io/repay-a-loan.md).

# Repay a loan

### Prerequisites

* A whitelisted borrower with current debt on an inventory pool

### Process Overview

1. Approve the inventory pool contract to spend your tokens
2. Call the `repay()` function directly on the inventory pool contract

### Step 1: Approve Token Spending

First, get the token address from the inventory pool and approve it to spend your tokens:

```javascript
// Using ethers.js
const inventoryPoolContract = new ethers.Contract(
  inventoryPoolAddress,
  [
    "function asset() view returns (address)"
  ],
  signer
);

// Get the token address from the inventory pool
const tokenAddress = await inventoryPoolContract.asset();

// Set up the token contract
const tokenContract = new ethers.Contract(
  tokenAddress,
  [
    "function approve(address spender, uint256 amount) returns (bool)",
    "function decimals() view returns (uint8)"
  ],
  signer
);

const decimals = await tokenContract.decimals();
const amount = ethers.parseUnits("1000.0", decimals);

// Approve the inventory pool to spend your tokens
const tx = await tokenContract.approve(inventoryPoolAddress, amount);
await tx.wait();
```

### Step 2: Repay the Loan

After approval, call the `repay()` function on the inventory pool contract. Note that the borrower parameter can be any address that has an active loan - it doesn't have to be the caller of the function:

```javascript
// Using ethers.js
const inventoryPoolContract = new ethers.Contract(
  inventoryPoolAddress,
  [
    "function repay(uint256 amount, address borrower)"
  ],
  signer
);

// Repay the loan
const tx = await inventoryPoolContract.repay(amount, borrowerAddress);
await tx.wait();
```

### Important Notes

* If repayment amount exceeds debt, the inventory pool will take the exact amount owed
