> ## 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.

# Delegated + Gasless

> Backend-controlled delegated execution with Safe-based gasless submission in the Ostium SDK.

`createDelegatedAndGasless()` is the most operationally advanced mode.

* the trader EOA owns USDC and positions
* a delegate EOA signs the delegated action
* the delegate's Safe submits it as a sponsored user operation

## When to use it

* backend-driven products that want custody separation and gasless submission
* high-volume builder integrations
* systems that already operate a Safe or Pimlico flow

## One-time trader setup

The trader must approve USDC and register the delegate Safe, not the delegate EOA:

```ts theme={null}
await traderClient.approveUsdc('max');
await traderClient.setDelegate('0xDelegateSafeAddress');
```

You can get that Safe address from `client.getSmartAccountAddress()`.

## Submit-capable client

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

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

```ts theme={null}
const client = await OstiumClient.createDelegatedAndGasless({
  delegatePrivateKey: process.env.DELEGATE_PRIVATE_KEY as `0x${string}`,
  traderAddress: '0xTraderAddress',
  safeAddress: '0xDelegateSafeAddress',
});
```

## Build-only client

```ts theme={null}
const client = await OstiumClient.createDelegatedAndGasless({
  traderAddress: '0xTraderAddress',
  delegateAddress: '0xDelegateAddress',
  safeAddress: '0xDelegateSafeAddress',
});
```

In build-only mode, `get*Tx()` returns a Safe-style request whose call data is already wrapped for delegated execution.

## Parameters

| Field                 | Type          | Required                            | Notes                                                                                                                                         |
| --------------------- | ------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `delegatePrivateKey`  | `0x${string}` | Submit-capable                      | Delegate EOA key. A Safe is derived from it and submits via Pimlico.                                                                          |
| `traderAddress`       | `0x${string}` | Yes                                 | Trader the delegate acts for. Must have called `setDelegate(safeAddress)` with the derived Safe (`client.getSmartAccountAddress()`).          |
| `delegateAddress`     | `0x${string}` | Build-only                          | Delegate EOA that owns the Safe.                                                                                                              |
| `safeAddress`         | `0x${string}` | Build-only; optional submit-capable | Required for build-only. Optional with `delegatePrivateKey` 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).
