> For the complete documentation index, see [llms.txt](https://city-protocol.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://city-protocol.gitbook.io/docs/software-development-kit/lending-borrowing/morpho-blue.md).

# Morpho Blue

Morpho Blue interactions follow a two-phase pattern. When you call any `build` method, the SDK returns an object containing `requirements` (prerequisite transactions like token approvals or authorizations) and a `bundlerTx` (the actual protocol call). Your app is responsible for sending these transactions in order.

#### Supply (Lend)

Supplies underlying assets into a Morpho Blue market as a lender. The SDK figures out what approvals or setup transactions are needed and returns them as `requirements`.

```
const prepared = await lendingClient.buildSupply({
  marketId: "0xYourMorphoMarketId",
  assets: 1_000_000n, // Amount in underlying token decimals
});
```

To execute, loop through the prerequisites first, then send the bundler transaction:

```
// Step 1: Send any prerequisite transactions (approvals, authorizations, etc.)
for (const tx of prepared.requirements) {
  await walletClient.sendTransaction({
    account,
    to: tx.to,
    data: tx.data,
    value: tx.value,
  });
}

// Step 2: Send the main bundler transaction
await walletClient.sendTransaction({
  account,
  to: prepared.bundlerTx.to,
  data: prepared.bundlerTx.data,
  value: prepared.bundlerTx.value,
});
```

This two-step pattern is the same for all Morpho Blue write operations. The examples below omit the execution step for brevity, but the flow is always: build, send requirements, send bundler tx.

#### Borrow

Borrows assets from a Morpho Blue market against your posted collateral. The returned object follows the same `{ requirements, bundlerTx }` shape as supply.

```
const prepared = await lendingClient.buildBorrow({
  marketId: "0xYourMorphoMarketId",
  assets: 500_000n, // Amount to borrow in underlying token decimals
});
```

**Note:** You need sufficient collateral posted in the market before calling this. If the borrow would put your position above the market's maximum LTV, the transaction will revert on-chain.

#### Repay

Repays borrowed assets on a Morpho Blue market. Requirements will typically include a token approval for the repayment amount.

```
const prepared = await lendingClient.buildRepay({
  marketId: "0xYourMorphoMarketId",
  assets: 500_000n, // Amount to repay in underlying token decimals
});
```

#### Withdraw

Withdraws previously supplied assets from a Morpho Blue market.

```
const prepared = await lendingClient.buildWithdraw({
  marketId: "0xYourMorphoMarketId",
  assets: 500_000n,
});
```
