> 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://exchange-api.gammaswap.com/api</code></td><td><code>InfoClient</code>, <code>ExchangeClient</code></td></tr><tr><td>Market WebSocket</td><td><code>wss://exchange-api.gammaswap.com/ws/</code></td><td><code>ExchangeWebSocketClient</code></td></tr><tr><td>Oracle WebSocket</td><td><code>wss://exchange-api.gammaswap.com/oracle-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` |
| Market 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://exchange-api.gammaswap.com/api
MARKET_WS_URL=wss://exchange-api.gammaswap.com/ws/
ORACLE_WS_URL=wss://exchange-api.gammaswap.com/oracle-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 market WebSocket

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

const marketStream = createExchangeWebSocketClient({
  websocketUrl: process.env.MARKET_WS_URL!,
  onError: (error) => console.error("Market stream error", error),
});

await marketStream.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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
