> For the complete documentation index, see [llms.txt](https://docs.enclave.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enclave.money/introducing-enclave-money/magicspend++/getting-started-with-turnkey/fetching-a-quote.md).

# Fetching a quote

Fetching a quote requires the client to specify the following inputs:

1. **walletAddress:** The user's EVM or Solana wallet address
2. **chainId**: Chain ID of the target chain
3. **amount:** How much they want to spend on the target chain
4. **type:** The type of quote the user is fetching. Learn more about quote types [here](https://docs.enclave.money/introducing-enclave-money/magicspend++#quote-types).
5. **settlementToken:** The token the user will settle in (ex. USDC or SOL)
6. **spendingTokenAddress:** The token the user wants to borrow and spend on the target chain
7. &#x20;**transactions:** A list of transaction objects representing the actions the user wants to execute on the target chain. These could be any type of transaction including transfers, swaps, depositing to yield protocols, buying an NFT, etc.

#### Importing libraries

```javascript
import axios from 'axios';
```

#### Defining types

```javascript
enum QuoteType {
  AMOUNT_IN = 'AMOUNT_IN',
  AMOUNT_OUT = 'AMOUNT_OUT'
}

type Transaction = {
  to: string;      // destination contract/address (0x-prefixed)
  data: string;    // calldata (0x-prefixed)
  value: string;   // value in wei (as string)
};

type GetQuoteParams = {
  // Solution inputs
  walletAddress: string;            // registered EVM address or Solana Address
  chainId: number;                  // chain ID
  amount: string;                   // smallest units, e.g. "200000" for 0.2 USDC
  type: QuoteType;                  // borrow mode (AMOUNT_IN or AMOUNT_OUT)
  settlementToken?: string | null;  // 'SOL' for SOL settlement, USDC by default
  spendingTokenAddress?: string | null;    // USDC by default, specify address of token on the chain corresponding to the given chainId

  // New: explicit call bundle the solver should execute
  transactions?: Transaction[]; // [{ to, data, value }, ...]
};

type QuoteResponse = type Quote = {
  chainId: number;
  tokenAddress: string;
  
  // Amount the user pays from source chains
  settlementAmount: string;
  
  // Expected amount of tokens the user will have on the target chain after borrowing
  expectedAmountOut: string;

  // Map of chain IDs to amounts to be settled from the corresponding chain
  settlementPlan: Record<string, string>;
};
```

#### Setting up request headers

```javascript
const headers = {
  'Content-Type': 'application/json',
  'Authorization': process.env.ENCLAVE_API_KEY,
};
```

#### Calling the quote API

<pre class="language-javascript"><code class="lang-javascript"><strong>export async function getQuote(params: GetQuoteParams): Promise&#x3C;QuoteResponse> {
</strong>  const {
    userId,
    walletAddress,
    outputNetwork,
    amount,
    type,
    settlementToken = null, // USDC by default
    spendingTokenAddress = null,   // USDC by default
    transactions = [],
  } = params;

  const { data } = await axios.post(
    `https://api.enclave.money/magicspend/quote`,
    {
      userId,
      walletAddress,
      outputNetwork,
      amount,
      type,
      settlementToken,
      spendingToken,
      transactions, // [{ to, data, value }]
    },
    {
      headers: headers
    }
  );
  
  const {
    expectedAmountOut,
    settlementAmount,
    settlementPlan
  } = data;
  
  console.log(`User receives: ${expectedAmountOut}`);
  console.log(`User pays: ${settlementAmount}`);
  console.log(`Payment split between networks: ${settlementPlan}`);

  return data
}
</code></pre>

{% hint style="info" %}
**Note on specifying spending amount:** The client specifies how much of a given token the user wants to spend. In the case where are user has 5$ on Base, but wants to lend a total of 10$ to a vault on Base, the client would set the amount field to 10$. Enclave will lend the user the 5$ deficit and fees will only be charged on the amount the user ends up borrowing.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.enclave.money/introducing-enclave-money/magicspend++/getting-started-with-turnkey/fetching-a-quote.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.
