> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ostium.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Self + Gasless

> Trader-owned positions with trader signatures and Safe-based gasless submission in the Ostium SDK.

`createSelfAndGasless()` keeps custody with the trader EOA but submits trades through a Safe smart account.

* the trader EOA owns USDC and positions
* the trader EOA signs the underlying trade action
* the trader's Safe submits the transaction as a sponsored user operation

## When to use it

* consumer apps that want a gasless UX
* embedded trading flows where the user should not need ETH after setup
* client-side apps that already have a Safe execution path

## One-time setup

The trader must do two EOA-signed transactions once:

```ts theme={null}
await client.approveUsdc('max');
await client.setupGaslessDelegation();
```

After that, trading calls can be sent gaslessly through the Safe.

## Submit-capable client

```ts theme={null}
const client = await OstiumClient.createSelfAndGasless({
  traderPrivateKey: process.env.TRADER_PRIVATE_KEY as `0x${string}`,
  pimlicoUrl: 'https://builder.prod.bedrock.ostium.io/v1/pimlico/sponsor?chainId=42161',
});
```

If you already know the Safe address for this trader key and chain, pass `safeAddress` to skip the SDK's smart-account derivation call during construction:

```ts theme={null}
const client = await OstiumClient.createSelfAndGasless({
  traderPrivateKey: process.env.TRADER_PRIVATE_KEY as `0x${string}`,
  safeAddress: '0xSafeAddress',
});
```

## Build-only client

```ts theme={null}
const client = await OstiumClient.createSelfAndGasless({
  traderAddress: '0xTraderAddress',
  safeAddress: '0xSafeAddress',
});

const tx = client.getOpenTradeTx({
  pairId: 0,
  buy: true,
  price: '65000',
  collateral: '100',
  leverage: '5',
  type: OrderType.Market,
});
```

In build-only mode, `get*Tx()` returns a Safe-style request with `safeAddress` and `calls`.

## Parameters

| Field                 | Type          | Required                            | Notes                                                                                                                                       |
| --------------------- | ------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `traderPrivateKey`    | `0x${string}` | Submit-capable                      | Trader EOA key. A Safe is derived from it to relay trades gaslessly.                                                                        |
| `traderAddress`       | `0x${string}` | Build-only                          | Trader EOA address.                                                                                                                         |
| `safeAddress`         | `0x${string}` | Build-only; optional submit-capable | Required for build-only. Optional with `traderPrivateKey` when you already know the deterministic Safe address and want to skip derivation. |
| `pimlicoUrl`          | `string`      | Optional                            | Bundler/paymaster URL. Defaults to the Ostium sponsor URL (chain-aware).                                                                    |
| `rpcUrl`              | `string`      | Optional                            | RPC URL for reads/simulation. Defaults to the public RPC.                                                                                   |
| `sponsorshipPolicyId` | `string`      | Optional                            | Pimlico sponsorship policy ID.                                                                                                              |

Plus the shared options (`testnet`, `slippageBps`, `builder`, `subgraphUrl`, `builderApiUrl`, `alchemyApiKey`). See [Client Configuration](/developer/client-modes/configuration).
