# For lending apps

Offer loans against Bitcoin that never leaves the Bitcoin network, with MaxyLock. The borrower locks BTC in Bitcoin scripts and receives the loan on the host chain. Nothing is wrapped, bridged or held by a custodian. For lending markets, wallets and treasury apps whose users hold BTC and want to borrow against it.

## How a MaxyLock loan fits

Each loan is between one borrower and one lender, on terms both signed. In the loans Maxy offers, Maxy is the lender, and Maxy's service does the lender's part.

| | MaxyLock |
| --- | --- |
| Collateral | BTC in Bitcoin scripts, 1 to 7 tranches, each repaid on its own |
| Loan | USDC or USDG, in the SDK's markets `base-mainnet` and `robinhood-mainnet` |
| Proof | The contract pays the principal only after a Bitcoin proof, with no oracle or committee |
| Price feed | None. A fall in the Bitcoin price does not, by itself, cost the borrower the collateral |
| Administrator | Cannot touch funds. The one privileged power is to pause new loans |
| If the lender withholds the secret | Its collateral buys the borrower Bitcoin at a premium: 105% in live vaults |

The live vault values, such as a 1-day term and a 7 USDC smallest loan, are on [How MaxyLock works](https://maxy.co/docs/how-maxylock-works#live-vault-values).

## Two ways to build

| You want | Do this | Read |
| --- | --- | --- |
| Maxy's loans in your app | Use the SDK's `borrow` calls: Maxy lends, your app runs the borrower's side | [Borrow with the SDK](https://maxy.co/docs/borrow-with-the-sdk) |
| To run the loan yourself, as a wallet or a lender | Call the loan contract directly, and run a watcher | [Wallets and lenders](https://maxy.co/docs/wallets-and-lenders) |

## What to build

1. **Sign the wallet in.** Loans act for one wallet: `maxy.auth.signIn`. A wallet's first sign-in needs a username.
2. **Quote and show it.** `borrow.listVaults`, then `borrow.quote` for an amount. If `canBorrow` is false, show the quote anyway, keep the button live, and show `blockedReason` on click.
3. **Agree and sign the terms.** `borrow.createRequest`, then `borrow.signTerms`. The SDK rebuilds and checks every term before the wallet signs; a plan that fails is `verification_failed`, with nothing signed.
4. **Fund.** The borrower sends one Bitcoin transaction with one output per tranche, each for the exact amount: `borrow.fund`. If its outcome is `ambiguous`, do not fund again: look the txid up first.
5. **Pay out.** Follow the loan with `borrow.trackLoan` until it is active, then `borrow.claimPayout`.
6. **Repay.** `borrow.repay` before `lastSafeRepayTime`. Maxy's service reveals the secret and the BTC comes back: [Repaying](https://maxy.co/docs/repaying-and-defaults#repaying).
7. **Watch for a missed reveal.** `getLoan(...).status.revealMissed` lists the tranche, and `startLiquidation` starts it: [If someone defaults](https://maxy.co/docs/repaying-and-defaults#if-someone-defaults).

The whole flow in code, with every refusal and what to do: [Borrow with the SDK](https://maxy.co/docs/borrow-with-the-sdk).

## Keys and testing

Loans run with your live secret key and the signed-in wallet's session. They have no sandbox: a test key answers `sandbox_refused` for a loan call, so the first loan runs on mainnet with real BTC and real gas. Start small, and keep the EVM and Bitcoin private keys in your own key store, never in code. With no gas to repay, `borrow.requestGas` sends a small amount.

## Running it yourself

A wallet that runs the loan itself needs a host-chain RPC and a Bitcoin node or indexer that returns raw transactions, headers and Merkle branches. Many contract calls are open to anyone, and a party that is offline at the wrong moment loses by it, so run a watcher. A lender holds three credentials on separate systems and must reveal at once on every repayment: [Lender operations](https://maxy.co/docs/wallets-and-lenders#lender-operations).

Every field, signature, event and revert reason: the [MaxyLock documentation (PDF)](https://maxy.co/docs/_media/maxylock-guide/maxylock-documentation.pdf).

---
Source: https://maxy.co/docs/for-lending-apps (Maxy Docs › Maxy for your app › Use cases)
