# `createSafeClient`

Returns an instance of the `SafeClient` class, which enables developers to configure new or existing Safe accounts and handle transactions.

The `SafeClient` class provides a mechanism to extend its functionality via the [`extend`](./extend.mdx) method.

## Usage


<Tabs items={['Existing Safe', 'New Safe']}>
  <Tabs.Tab>
    

    ```typescript   
    import { createSafeClient } from '@safe-global/sdk-starter-kit'

    const safeClient = await createSafeClient({
      provider,
      signer,
      safeAddress: '0x...',
      apiKey: 'YOUR_API_KEY', // Necessary for Safe API interactions
      txServiceUrl = 'https://...' // Optional. Use it if you run your own service
    })
    ```

    Use the `safeAddress` property to use an existing Safe account.
  </Tabs.Tab>
  <Tabs.Tab>
    ```typescript 
    import { createSafeClient } from '@safe-global/sdk-starter-kit'

    const safeClient = await createSafeClient({
      provider,
      signer,
      safeOptions: {
        owners: ['0x...', '0x...', '0x...'],
        threshold: 2,
        saltNonce: '123'
      },
      apiKey: 'YOUR_API_KEY', // Necessary for Safe API interactions
      txServiceUrl = 'https://...' // Optional. Use it if you run your own service
    })
    ```

    Use the `safeOptions` property to configure and deploy a new Safe account. The Safe address generation is deterministic based on the `owners`, `threshold`, and `saltNonce` values. 
  </Tabs.Tab>
</Tabs>


## Returns

`Promise<SafeClient>`

A new instance of the `SafeClient` class.

## Parameters

### `provider`

- **Type:** `Eip1193Provider | HttpTransport | SocketTransport`

The provider connected to the blockchain.

```typescript focus=2
const safeClient = await createSafeClient({
  provider,
  signer,
  safeAddress: '0x...',
  apiKey: 'YOUR_API_KEY'
})
```

### `signer`

- **Type:** `HexAddress | PrivateKey | PasskeyClient`

The signer connected to the Safe as an owner.
- If it's an address, the same address from the `provider` will be used to sign.
- If it's a private key, its derived address will be used to sign.
- If it's a passkey, the passkey will be used to sign.

```typescript focus=3
const safeClient = await createSafeClient({
  provider,
  signer,
  safeAddress: '0x...',
  apiKey: 'YOUR_API_KEY'
})
```

### `safeAddress` (Optional)

- **Type:** `HexAddress`

The address of the connected Safe.

```typescript focus=4
const safeClient = await createSafeClient({
  provider,
  signer,
  safeAddress: '0x...',
  apiKey: 'YOUR_API_KEY'
})
```

### `safeOptions.owners` (Optional)

- **Type:** `string[]`

The list of owners to configure in the Safe.

```typescript focus=5
const safeClient = await createSafeClient({
  provider,
  signer,
  safeOptions: {
    owners: ['0x...', '0x...', '0x...'],
    threshold: 2,
    saltNonce: '123'
  },
  apiKey: 'YOUR_API_KEY'
})
```

### `safeOptions.threshold` (Optional)

- **Type:** `number`

The threshold of the Safe. It must be lower or equal to the number of owners.

```typescript focus=6
const safeClient = await createSafeClient({
  provider,
  signer,
  safeOptions: {
    owners: ['0x...', '0x...', '0x...'],
    threshold: 2,
    saltNonce: '123'
  },
  apiKey: 'YOUR_API_KEY'
})
```

### `safeOptions.saltNonce` (Optional)

- **Type:** `string`

The salt introduces randomness or predictability when the Safe address is generated.

```typescript focus=7
const safeClient = await createSafeClient({
  provider,
  signer,
  safeOptions: {
    owners: ['0x...', '0x...', '0x...'],
    threshold: 2,
    saltNonce: '123'
  }
  apiKey: 'YOUR_API_KEY'
})
```

### `apiKey` (Optional)

- **Type:** `string`

The API key for the Safe Transaction Service. This parameter is mandatory when using default Safe provided services. It can be omitted if using a custom Transaction Service. [Check how to get one](/core-api/how-to-use-api-keys.mdx).

```typescript focus=5
const safeClient = await createSafeClient({
  provider,
  signer,
  safeAddress: '0x...',
  apiKey: 'YOUR_API_KEY'
})
```

### `txServiceUrl` (Optional)

- **Type:** `string`

The URL of the Safe Transaction Service. This can be provided instead of `apiKey` to specify a custom Transaction Service endpoint, such as when running your own Safe Transaction Service instance.

```typescript focus=5
const safeClient = await createSafeClient({
  provider,
  signer,
  safeAddress: '0x...',
  txServiceUrl: 'https://...'
})
```
