> For the complete documentation index, see [llms.txt](https://docs.flash.trade/flash-trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flash.trade/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-api/flash-trade-v2/workflows/setupintegration.md).

# SetupIntegration

Guide for setting up a Flash Trade **v2** integration from scratch.

## 1. Verify connectivity

```bash
export FLASH_API_URL="https://flashapi.trade"          # API host (v2 lives under /v2)
export SOLANA_RPC_URL="https://api.mainnet-beta.solana.com"
export V2_RPC_URL="<v2-rpc-endpoint>"                   # for v2 trade submission

# Health + reference data
curl $FLASH_API_URL/v2/health
curl $FLASH_API_URL/v2/tokens
curl $FLASH_API_URL/v2/prices
```

## 2. Know where to submit

Each endpoint's transaction submits to one of two RPC endpoints. Get this right or submissions will fail:

| Endpoint group                                                                                                        | Submit to        |
| --------------------------------------------------------------------------------------------------------------------- | ---------------- |
| `init-deposit-ledger`, `init-basket`, `deposit-direct`, `delegate-basket`, `request-withdrawal`, `execute-withdrawal` | `SOLANA_RPC_URL` |
| All trading endpoints (`open/close/reverse`, collateral, triggers, limits)                                            | `V2_RPC_URL`     |

## 3. Dependencies (by language)

| Language   | HTTP Client          | Solana Signing       | Basket Decoding           |
| ---------- | -------------------- | -------------------- | ------------------------- |
| TypeScript | `fetch` (built-in)   | `@solana/web3.js`    | v2 client SDK             |
| Python     | `requests` / `httpx` | `solders`            | decode raw bytes manually |
| Rust       | `reqwest`            | `solana-sdk`         | v2 Rust SDK               |
| Any        | Any HTTP client      | base64 decode + sign | SDK or manual Borsh       |

> To turn the streamed `basketData` bytes into native `PositionMeta[]` / `OrderMeta[]`, use the v2 client SDK. The API's `positionMetrics` / `orderMetrics` already give you UI-ready strings if you don't need the raw structs.

## 4. One-time wallet setup

A wallet must be initialized and delegated before it can trade. Build each transaction via the API, sign with the owner, submit to your **Solana RPC**, and confirm:

```bash
# Deposit ledger + basket
curl -X POST $FLASH_API_URL/v2/transaction-builder/init-deposit-ledger -H 'Content-Type: application/json' -d '{ "owner": "<WALLET>" }'
curl -X POST $FLASH_API_URL/v2/transaction-builder/init-basket         -H 'Content-Type: application/json' -d '{ "owner": "<WALLET>" }'

# Deposit collateral (UI amount; server converts to native).
# Source ATA + token program are derived server-side from owner + tokenMint.
curl -X POST $FLASH_API_URL/v2/transaction-builder/deposit-direct -H 'Content-Type: application/json' -d '{
  "owner": "<WALLET>",
  "tokenMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "amount": "100.0"
}'

# Delegate the basket
curl -X POST $FLASH_API_URL/v2/transaction-builder/delegate-basket -H 'Content-Type: application/json' -d '{
  "payer": "<WALLET>", "owner": "<WALLET>"
}'
```

## 5. Verify your integration

1. **Read market data?** `GET /v2/prices`, `GET /v2/tokens`.
2. **Read wallet state?** `GET /v2/owner/<WALLET>` (basket snapshot).
3. **Build a quote?** `open-position` without `owner` (preview-only).
4. **Trade?** Build `open-position`, sign, submit to the v2 RPC, then confirm via the basket snapshot/WS.

Next: [BuildTransaction](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-api/flash-trade-v2/workflows/buildtransaction.md).


---

# 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.flash.trade/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-api/flash-trade-v2/workflows/setupintegration.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.
