# Create User

> Register a new user sub-account under your builder and get their API key.

## Usage

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

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

const result = await builder.createUser('0xUserWalletAddress...');

console.log(result.walletAddress);    // User's login wallet address
console.log(result.multiSigWallet);   // User's Gnosis Safe wallet address
console.log(result.apikey);           // User's API key - SAVE THIS!
console.log(result.builderName);      // Builder name
console.log(result.enableTrading);    // Whether trading is enabled
```

## Parameters

| Parameter       | Type   | Required | Description                             |
| --------------- | ------ | -------- | --------------------------------------- |
| `walletAddress` | string | Yes      | User's EOA wallet address (0x-prefixed) |

## Response

```typescript
interface UserInfo {
  apikey: string;              // API key (only returned during creation)
  walletAddress: string;       // User's login wallet address
  multiSigWallet: string;     // User's Gnosis Safe wallet address
  builderName: string;        // Builder name
  walletCreationTxHash?: string; // Safe creation transaction hash
  enableTrading: boolean;      // Whether trading approvals are set up
}
```

## Notes

* The API key is returned **only once** during creation. Store it securely in your database.
* The Gnosis Safe wallet is created asynchronously (1-10 minutes). Poll `getUser()` until `multiSigWallet` is non-empty.
* If the user already exists, the API will return an error. Use `getUser()` to retrieve existing user info.

### Polling for Safe Wallet

```typescript
// Poll until Safe wallet is ready
let safeAddress = result.multiSigWallet;
while (!safeAddress) {
  await new Promise((r) => setTimeout(r, 30_000)); // Wait 30s
  const user = await builder.getUser('0xUserWalletAddress...');
  safeAddress = user.multiSigWallet;
}
console.log('Safe wallet ready:', safeAddress);
```
