> For the complete documentation index, see [llms.txt](https://docs.cometh.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cometh.io/integrations/react-hooks/session-keys/usegrantpermission.md).

# useGrantPermission

## Returns:

| Property             | Type                                                                                                       | Description                                                                                                                 |
| -------------------- | ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| data                 | GrantPermissionMutateResponse or undefined                                                                 | The response object containing the transaction hash and session details if the mutation is successful, otherwise undefined. |
| error                | Error or null                                                                                              | An error object if the transaction failed, otherwise null.                                                                  |
| isPending            | boolean                                                                                                    | A boolean indicating whether the transaction is currently pending.                                                          |
| isSuccess            | boolean                                                                                                    | A boolean indicating whether the transaction was successfully sent.                                                         |
| isError              | boolean                                                                                                    | A boolean indicating whether an error occurred during the transaction process.                                              |
| grantPermission      | (variables: GrantPermissionParameters\<ComethSafeSmartAccount>) => void                                    | A function to trigger the grant permission for a sessionKey.                                                                |
| grantPermissionAsync | (variables: GrantPermissionParameters\<ComethSafeSmartAccount>) => Promise\<GrantPermissionMutateResponse> | A function to trigger the grant permission for a sessionKey and return a promise resolving to the transaction details.      |

GrantPermissionMutateResponse Structure:

```typescript
type GrantPermissionMutateResponse = {
  txHash: Hash;
  createSessionsResponse: GrantPermissionResponse;
};
```

## Explanation:

• txHash: The hash of the transaction that was sent to the blockchain.

• createSessionsResponse: The response from the grantPermission operation, including details about the session and its status.

## Usage Example:

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

const Component = () => {
  const {
    data,
    error,
    isPending,
    isSuccess,
    isError,
    grantPermission,
    grantPermissionAsync,
  } = useGrantPermission();

  const handleGrantPermission = () => {
    grantPermission(permission);
  };

  const handleAsyncGrantPermission = async () => {
    try {
      const result = await grantPermissionAsync(permission);
      console.log("Transaction hash:", result.txHash);
    } catch (err) {
      console.error("Permission grant failed:", err);
    }
  };

  return (
    <div>
      {isPending && <p>Granting permission...</p>}
      {isSuccess && <p>Permission granted successfully!</p>}
      {isError && <p>Error: {error?.message}</p>}
      <button onClick={handleGrantPermission}>Grant Permission</button>
      <button onClick={handleAsyncGrantPermission}>Grant Permission (Async)</button>
    </div>
  );
};
```

## How It Works:

The hook relies on the smartAccountClient to extend actions from the cometh/connect-sdk-4337 package. It executes the following steps:

1\. Extends the smart account with necessary actions (erc7579Actions, smartSessionActions).

2\. Calls the grantPermission method with the provided parameters.

3\. Waits for confirmation using waitForUserOperationReceipt.

4\. Returns the transaction hash and the session response.

## Example of Expected Response:

```json
{
  "txHash": "0x123abc456def...",
  "createSessionsResponse": {
    "userOpHash": "0x789xyz...",
    "session": ...,
    "permissionIds": ...;
    "action": ...;
  }
}
```

## Error Handling:

If the mutation fails, the error object provides details about the failure, which can be used to display custom error messages to users.

## Mutation Props (mutationProps):

The hook accepts optional custom mutation parameters through the MutationOptionsWithoutMutationFn object, allowing you to adjust its behavior if needed.
