> For the complete documentation index, see [llms.txt](https://docs.gammaswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gammaswap.com/developers/getting-started/connect.md).

# Connect

GammaSwap provides separate endpoints for HTTP requests, market updates, oracle prices, and on-chain deposit operations.

### Service URLs

<table><thead><tr><th>Service</th><th width="181.8828125">Production URL</th><th>Used by</th></tr></thead><tbody><tr><td>Exchange HTTP API</td><td><code>https://external-api.gammaswap.com/api</code></td><td><code>InfoClient</code>, <code>ExchangeClient</code></td></tr><tr><td>Orderbook WebSocket</td><td><code>wss://external-api.gammaswap.com/ws/</code></td><td><code>ExchangeWebSocketClient</code></td></tr><tr><td>Oracle WebSocket</td><td><code>wss://oracle-api.gammaswap.com/ws/</code></td><td><code>OracleWebSocketClient</code></td></tr><tr><td>Chain RPC</td><td>Your RPC provider URL</td><td><code>DepositClient</code></td></tr></tbody></table>

Local service defaults:

| Service             | Local URL               |
| ------------------- | ----------------------- |
| Exchange HTTP API   | `http://localhost:3000` |
| Orderbook WebSocket | `ws://127.0.0.1:4000`   |
| Oracle WebSocket    | `ws://127.0.0.1:8082`   |

{% hint style="info" %}
Production HTTP requests use the `/api` base path. Local deployments are normally served without an `/api` prefix.
{% endhint %}

### Environment configuration

A server-side application can store connection settings in environment variables:

```bash
EXCHANGE_API_URL=https://external-api.gammaswap.com/api
ORDERBOOK_WS_URL=wss://external-api.gammaswap.com/ws/
ORACLE_WS_URL=wss://oracle-api.gammaswap.com/ws/

CHAIN_ID=84532
RPC_URL=https://your-rpc-provider.example
PRIVATE_KEY=0x...
```

Do not expose `PRIVATE_KEY` in frontend code, public environment variables, logs, or source control.

### Connect to the HTTP API

Read-only requests use `InfoClient`.

```ts
import { createInfoClient } from "@gammaswap/v2-exchange-sdk";

const info = createInfoClient({
  apiUrl: process.env.EXCHANGE_API_URL!,
});
```

Signed exchange actions use `ExchangeClient`.

```ts
import { createExchangeClient } from "@gammaswap/v2-exchange-sdk";
import { Wallet } from "ethers";

const wallet = new Wallet(process.env.PRIVATE_KEY!);

const exchange = createExchangeClient({
  apiUrl: process.env.EXCHANGE_API_URL!,
  wallet,
  chainId: process.env.CHAIN_ID!,
});
```

### Connect to the Orderbook WebSocket

```ts
import {
  createExchangeWebSocketClient,
} from "@gammaswap/v2-exchange-sdk";

const orderbookStream = createExchangeWebSocketClient({
  websocketUrl: process.env.ORDERBOOK_WS_URL!,
  onError: (error) => console.error("Orderbook stream error", error),
});

await orderbookStream.connect();
```

Calling `connect()` is optional before subscribing. Subscription methods establish the connection when necessary.

### Connect to the Oracle WebSocket

```ts
import {
  createOracleWebSocketClient,
} from "@gammaswap/v2-exchange-sdk";

const oracleStream = createOracleWebSocketClient({
  websocketUrl: process.env.ORACLE_WS_URL!,
  onError: (error) => console.error("Oracle stream error", error),
});

await oracleStream.connect();
```

### Connect to the chain

`DepositClient` connects to an EVM JSON-RPC provider.

```ts
import { createDepositClient } from "@gammaswap/v2-exchange-sdk";
import { Wallet } from "ethers";

const wallet = new Wallet(process.env.PRIVATE_KEY!);

const deposit = createDepositClient({
  rpcUrl: process.env.RPC_URL!,
  wallet,
  chainId: process.env.CHAIN_ID!,
});
```

The client verifies that the RPC network matches the configured `chainId` before performing contract reads or transactions.

### Chain IDs and contracts

The supplied SDK examples use Base Sepolia:

| Network      | Chain ID |
| ------------ | -------: |
| Base Sepolia |  `84532` |

When the SDK includes default contract addresses for a chain, it resolves those contracts automatically.

For a custom or unsupported deployment, provide contract overrides:

```ts
const exchange = createExchangeClient({
  apiUrl: process.env.EXCHANGE_API_URL!,
  wallet,
  chainId: process.env.CHAIN_ID!,
  contracts: {
    // Exchange contract overrides
  },
});
```

For deposits, the deposit-ledger address can be supplied directly:

```ts
const deposit = createDepositClient({
  rpcUrl: process.env.RPC_URL!,
  wallet,
  chainId: process.env.CHAIN_ID!,
  depositLedger: "0x...",
});
```

The production chain ID and production RPC provider are not specified in the supplied developer documentation.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gammaswap.com/developers/getting-started/connect.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
