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

# useCreateSession

> Hook for creating a session key.

Use the `useCreateSession` hook to create a session key for the connected Abstract Global Wallet.

## Import

```tsx theme={null}
import { useCreateSession } from "@abstract-foundation/agw-react";
```

## Usage

```tsx theme={null}
import { useCreateSession } from "@abstract-foundation/agw-react";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { LimitType } from "@abstract-foundation/agw-client/sessions";
import { toFunctionSelector, parseEther } from "viem";

export default function CreateSessionExample() {
  const { createSessionAsync } = useCreateSession();

  async function handleCreateSession() {
    const sessionPrivateKey = generatePrivateKey();
    const sessionSigner = privateKeyToAccount(sessionPrivateKey);

    const { session, transactionHash } = await createSessionAsync({
      session: {
        signer: sessionSigner.address,
        expiresAt: BigInt(Math.floor(Date.now() / 1000) + 60 * 60 * 24), // 24 hours
        feeLimit: {
          limitType: LimitType.Lifetime,
          limit: parseEther("1"), // 1 ETH lifetime gas limit
          period: BigInt(0),
        },
        callPolicies: [
          {
            target: "0xC4822AbB9F05646A9Ce44EFa6dDcda0Bf45595AA", // Contract address
            selector: toFunctionSelector("mint(address,uint256)"), // Allowed function
            valueLimit: {
              limitType: LimitType.Unlimited,
              limit: BigInt(0),
              period: BigInt(0),
            },
            maxValuePerUse: BigInt(0),
            constraints: [],
          }
        ],
        transferPolicies: [],
      }
    });
  }

  return <button onClick={handleCreateSession}>Create Session</button>;
}
```

## Returns

<ResponseField name="createSession" type="function">
  Function to create a session key. Returns a Promise that resolves to the created session configuration.

  ```ts theme={null}
  {
    transactionHash: Hash | undefined; // Transaction hash if deployment was needed
    session: SessionConfig; // The created session configuration
  }
  ```
</ResponseField>

<ResponseField name="createSessionAsync" type="function">
  Async mutation function to create a session key for `async` `await` syntax.
</ResponseField>

<ResponseField name="isPending" type="boolean">
  Whether the session creation is in progress.
</ResponseField>

<ResponseField name="isError" type="boolean">
  Whether the session creation resulted in an error.
</ResponseField>

<ResponseField name="error" type="Error | null">
  Error object if the session creation failed.
</ResponseField>
