> For the complete documentation index, see [llms.txt](https://docs.opinion.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opinion.trade/developer-guide/opinion-clob-typescript-sdk/builder-mode/enable-trading.md).

# Enable Trading

> Build, sign, and submit a one-time approval transaction for a user's Safe wallet.

## Usage

```typescript
import { BuilderClient, UserClient } from '@opinion-labs/opinion-clob-sdk';

const builder = new BuilderClient({
  host: 'https://openapi.opinion.trade/openapi',
  builderApiKey: 'YOUR_BUILDER_KEY',
  chainId: 56,
  rpcUrl: 'https://bsc-dataseed.binance.org',
});

// Step 1: Build the Enable Trading transaction
const txResult = await builder.buildEnableTradingTx(safeAddress);

console.log(txResult.safeTx);       // Safe transaction parameters
console.log(txResult.eip712Data);   // EIP-712 typed data for signing
console.log(txResult.safeTxHash);   // Safe transaction hash

// Step 2: User signs the EIP-712 typed data
const user = new UserClient('0xUserPrivateKey...');
const signature = await user.signTypedData(txResult.eip712Data);

// Step 3: Submit to backend for relay
const result = await builder.submitSafeTx(userAddress, txResult, signature);
```

## Parameters

### buildEnableTradingTx

| Parameter     | Type                    | Required | Description                                                        |
| ------------- | ----------------------- | -------- | ------------------------------------------------------------------ |
| `safeAddress` | string                  | Yes      | User's Gnosis Safe wallet address                                  |
| `quoteTokens` | Record\<string, string> | No       | Map of token address to exchange address. Auto-fetched if omitted. |

### submitSafeTx

| Parameter       | Type         | Required | Description                            |
| --------------- | ------------ | -------- | -------------------------------------- |
| `walletAddress` | string       | Yes      | User's wallet address (Safe owner EOA) |
| `safeTxResult`  | SafeTxResult | Yes      | Result from `buildEnableTradingTx()`   |
| `signature`     | string       | Yes      | User's signature on the EIP-712 data   |

## Response

`buildEnableTradingTx()` returns a `SafeTxResult`:

```typescript
interface SafeTxResult {
  safeTx: SafeTxParams;          // Raw Safe transaction parameters
  eip712Data: {                  // EIP-712 data for wallet signing
    types: Record<string, Array<{ name: string; type: string }>>;
    primaryType: string;         // 'SafeTx'
    domain: Record<string, unknown>;
    message: Record<string, unknown>;
  };
  safeTxHash: string;            // Hash of the Safe transaction
  submissionDataTemplate: Record<string, unknown>;
}
```

## Notes

* Enable Trading only needs to be called **once** per user. Check `userInfo.enableTrading` before calling.
* This operation requires `rpcUrl` in the BuilderClient config (used to read the Safe nonce).
* The transaction is relayed by the backend -- no gas is required from the user.
* Safe TX signing uses `user.signTypedData(eip712Data)`. This is different from order signing which uses `user.signHash(structHash)`.
* On-chain confirmation typically takes 30-60 seconds after submission.


---

# 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.opinion.trade/developer-guide/opinion-clob-typescript-sdk/builder-mode/enable-trading.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.
