> 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/core-concepts/gas-operations.md).

# Gas Operations

The Opinion CLOB SDK uses a hybrid execution model. Order matching occurs off-chain via CLOB infrastructure (gas-free), while direct smart contract operations require BNB for transaction fees.

## Gas-Free Operations

These operations are authenticated via EIP712 cryptographic signatures and submitted to the Opinion API. No gas is required.

Supported Operations:

* Market data queries (`getMarkets`, `getOrderbook`, `getLatestPrice`, etc.)
* Order management (`placeOrder`, `cancelOrder`, `placeOrdersBatch`, etc.)
* Position tracking (`getMyBalances`, `getMyPositions`, `getMyTrades`)

## Gas-Required Operations

These operations modify blockchain state and require BNB native token for gas fees.

| Operation       | Approx. Gas | Description                               |
| --------------- | ----------: | ----------------------------------------- |
| `enableTrading` |   \~100,000 | One-time ERC20/ERC1155 approvals          |
| `split`         |   \~150,000 | Convert collateral to outcome tokens      |
| `merge`         |   \~120,000 | Convert outcome tokens back to collateral |
| `redeem`        |   \~180,000 | Claim winning payouts after resolution    |

### Enable Trading

One-time approval to allow the exchange to use your tokens. Result is cached.

{% code title="example.ts" %}

```typescript
const result = await client.enableTrading();
if (result.txHash) {
  console.log(`Trading enabled. TX: ${result.txHash}`);
} else {
  console.log('Trading already enabled (cached)');
}
```

{% endcode %}

The return type is `TransactionResult`:

{% code title="types.ts" %}

```typescript
interface TransactionResult {
  txHash: string;
  safeTxHash: string;
  returnValue: string;
}
```

{% endcode %}

### Split

Convert collateral (USDT) into outcome token pairs (YES + NO).

{% code title="split.ts" %}

```typescript
// Split 100 USDT into YES + NO tokens
const amountWei = BigInt(100) * BigInt(10 ** 18);
const result = await client.split(
  123,       // marketId
  amountWei, // amount in wei
  true,      // checkApproval: auto-enable trading if needed
);
console.log(`Split TX: ${result.txHash}`);
```

{% endcode %}

Parameters:

* `marketId` (number) - The market ID
* `amount` (bigint) - Amount in wei
* `checkApproval` (boolean, default `true`) - Auto-call `enableTrading()` if needed

### Merge

Convert outcome token pairs back to collateral.

{% code title="merge.ts" %}

```typescript
const amountWei = BigInt(50) * BigInt(10 ** 18);
const result = await client.merge(123, amountWei, true);
```

{% endcode %}

Parameters:

* `marketId` (number) - The market ID
* `amount` (bigint) - Amount in wei
* `checkApproval` (boolean, default `true`) - Auto-call `enableTrading()` if needed

### Redeem

Claim winnings from resolved markets.

{% code title="redeem.ts" %}

```typescript
const result = await client.redeem(123, true);
```

{% endcode %}

Parameters:

* `marketId` (number) - The market ID (must be in RESOLVED status)
* `checkApproval` (boolean, default `true`) - Auto-call `enableTrading()` if needed

## Gas Cost Estimation

At typical BNB Chain conditions (0.05 Gwei gas price, \~$600/BNB):

| Operation       | Approximate Cost |
| --------------- | ---------------: |
| `enableTrading` |         \~$0.003 |
| `split`         |        \~$0.0045 |
| `merge`         |         \~$0.004 |
| `redeem`        |         \~$0.005 |

## Recommended BNB Balance

| Use Case       |     Recommended BNB |
| -------------- | ------------------: |
| Initial setup  | 0.001 BNB (\~$0.60) |
| Active trading |  0.01 BNB (\~$6.00) |
| High-frequency |  0.1 BNB (\~$60.00) |

## Optimization Strategy

{% stepper %}
{% step %}

### Enable trading once

Approval is cached, so you only need to call `enableTrading()` one time.
{% endstep %}

{% step %}

### Split in bulk

Create a large token inventory in one transaction to reduce the number of on-chain operations.
{% endstep %}

{% step %}

### Trade via CLOB

All order placement and cancellation are gas-free when performed via the CLOB off-chain infrastructure.
{% endstep %}

{% step %}

### Merge/Redeem when needed

Only perform `merge` or `redeem` when exiting positions or after market resolution.
{% endstep %}
{% endstepper %}
