# 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,
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://city-protocol.gitbook.io/docs/software-development-kit/lending-borrowing/morpho-blue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
