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

# createWithViewerKey

> Create an authenticated wallet viewer using a mnemonic or seed.

Creates a `SparkReadonlyClient` authenticated with an identity key derived from a mnemonic or seed. Can query a private wallet as its owner or as the viewer identity authorized by that owner.

Use a separate viewer mnemonic for services. Derive the public key with `deriveViewerIdentityPublicKey(config, mnemonicOrSeed, accountNumber)` and have the owner authorize it with [`setViewerIdentityPublicKey()`](https://docs.spark.money/api-reference/wallet/set-viewer-identity-public-key). Use the same network and account number for derivation and authentication. See the [complete setup](https://docs.spark.money/wallets/privacy.md#grant-a-service-read-access).

## Method Signature

```typescript theme={null}
static async createWithViewerKey(
  config: ConfigOptions | undefined,
  mnemonicOrSeed: Uint8Array | string,
  accountNumber?: number,
): Promise<SparkReadonlyClient>
```

## Parameters

**config** `ConfigOptions | undefined` *required*

Configuration options including network selection. Pass `undefined` for defaults.

**mnemonicOrSeed** `Uint8Array | string` *required*

BIP-39 mnemonic phrase, hex-encoded seed string, or raw seed bytes.

**accountNumber** `number`

Account index for key derivation. Defaults to `0` for REGTEST, `1` otherwise.

## Returns

**client** `Promise\<SparkReadonlyClient\>` *required*

An authenticated wallet viewer. Requests include an identity key signature for access to private wallet data.

## Example

```typescript From Mnemonic theme={null}
import { SparkReadonlyClient } from "@buildonspark/spark-sdk";

const client = await SparkReadonlyClient.createWithViewerKey(
  { network: "MAINNET" },
  viewerMnemonic, // The service’s own mnemonic, not the owner’s wallet mnemonic
);

// Query a wallet that granted this identity read access.
const balance = await client.getAvailableBalance("sp1...");
```

```typescript From Seed theme={null}
import { SparkReadonlyClient } from "@buildonspark/spark-sdk";

const client = await SparkReadonlyClient.createWithViewerKey(
  { network: "MAINNET" },
  seedBytes, // Uint8Array
  1,         // account number
);
```
