# useSessionKeySigner

## Returns:

| Property  | Type                                               | Description                                                                   |
| --------- | -------------------------------------------------- | ----------------------------------------------------------------------------- |
| data      | SafeSigner<"safeSmartSessionsSigner"> or undefined | The session key signer if it was successfully created, otherwise undefined.   |
| error     | Error or null                                      | An error object if the signer creation failed, otherwise null.                |
| isPending | boolean                                            | A boolean indicating whether the signer is currently being created.           |
| isSuccess | boolean                                            | A boolean indicating whether the session key signer was successfully created. |
| isError   | boolean                                            | A boolean indicating whether an error occurred during the signer creation.    |

## Usage Example:

```typescript
import { useSessionKeySigner } from "path/to/hook";

const Component = () => {
  const { data: sessionKeySigner, error, isPending, isSuccess, isError } =
    useSessionKeySigner({
      sessionData: { permissionIds: [...], action: "...", sessions: [...] },
      privateKey: "0xYOUR_PRIVATE_KEY",
    });

  if (isPending) return <p>Initializing session key signer...</p>;
  if (isError) return <p>Error: {error?.message}</p>;

  return (
    <div>
      {isSuccess && <p>Session Key Signer Initialized!</p>}
      <button
        onClick={() => {
          if (sessionKeySigner) {
            // Example usage: signing an operation
            console.log("Session Key Signer:", sessionKeySigner);
          }
        }}
      >
        Use Session Key Signer
      </button>
    </div>
  );
};
```

## How It Works:

The hook follows these steps to create the session key signer:

1\. Uses the smartAccountClient obtained from useSmartAccount.

2\. Extends the client using smartSessionActions and erc7579Actions.

3\. Converts the smart account into a session signer using the toSmartSessionsSigner utility.

4\. Returns the signer, which can then be used to sign permissioned operations.

Example of Expected Response:

```typescript
{
  "type": "safeSmartSessionsSigner",
  "signer": "Signer instance with session capabilities"
}
```

## Error Handling:

If an error occurs during the creation of the session key signer, the error object will provide information about what went wrong. This can be used to display helpful error messages to the user.

## Customization:

The query is controlled using wagmi’s useQuery. You can pass additional options (e.g., enabling/disabling the query dynamically) as needed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cometh.io/integrations/react-hooks/session-keys/usesessionkeysigner.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
