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

# useGetWallet

> Get an authenticated user Wallet

## Usage

```typescript theme={null}
const { fetchWallet, data, isLoading, error } = useGetWallet();
```

### Parameters

* `params` (`GetWalletParams`):
  * `externalUserId` (string): User ID from your auth provider
* `getBearerToken` (`() => Promise<string>`): Function returning the auth token
* `queryOptions` (`UseQueryOptions`, optional): React Query options (e.g. `enabled`)

### Return Value

Returns an object containing:

* `fetchWallet`: Function to manually fetch wallet data with custom params
* `data`: The wallet object (`publicKey`, `encryptedPrivateKey`, `walletType`, etc.)
* `isLoading`: Boolean indicating if the operation is in progress
* `isError`: Boolean indicating if an error occurred
* `isSuccess`: Boolean indicating if the query succeeded
* `error`: Any error that occurred during the process
* `refetch`: Function to re-run the query

## Example Implementation

```typescript theme={null}
import { useGetWallet } from "@chipi-stack/chipi-react";
import { useAuth } from "@clerk/nextjs";

export function WalletPage(){
  const { userId, getToken } = useAuth();

  const { data: wallet, isLoading, error, fetchWallet } = useGetWallet({
    params: {
      externalUserId: userId || "",
    },
    getBearerToken: async () => {
      const token = await getToken();
      if (!token) throw new Error("No token found");
      return token;
    },
    queryOptions: {
      enabled: Boolean(userId),
    },
  });

  // Or use fetchWallet manually:
  const loadWallet = async () => {
    if (!userId) return;
    try {
      const token = await getToken();
      if (!token) throw new Error("No token found");

      const wallet = await fetchWallet({
        params: {
          externalUserId: userId,
        },
        getBearerToken: async () => token,
      });

      console.log("Wallet loaded:", wallet);
    } catch (error) {
      console.error("Error loading wallet:", error);
    }
  };

  return (
    <div>
      {isLoading && <p>Loading wallet...</p>}
      {error && <p>Error: {error.message}</p>}
      {wallet && (
        <div>
          <p>Public Key: {wallet.publicKey}</p>
          <p>Normalized Public Key: {wallet.normalizedPublicKey}</p>
        </div>
      )}
    </div>
  );
}
```

<Note>
  Chipi never stores your decrypted sensitive data. All private keys and
  authentication tokens remain secure and are never accessible to Chipi servers.
</Note>
