# useSendPermission

## Returns:

| Property            | Type                                                   | Description                                                                                          |
| ------------------- | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
| data                | Hash or undefined                                      | The hash of the transaction if it was successfully sent, 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.                       |
| sendPermission      | (variables: UsePermissionParameters) => void           | A function to trigger the permission request using a sessionKey.                                     |
| sendPermissionAsync | (variables: UsePermissionParameters) => Promise\<Hash> | A function to trigger the permission request and return a promise resolving to the transaction hash. |

## Usage Example:

<pre class="language-typescript"><code class="lang-typescript">import { useSendPermission } from "path/to/hook";

const Component = () => {
  const {
    data,
    error,
    isPending,
    isSuccess,
    isError,
    sendPermission,
    sendPermissionAsync,
  } = useSendPermission({
    sessionData: ..., 
    privateKey: ...,
  });

  const handleSendPermission = () => {
    sendPermission({
      actions: [
        {
          target: 0x012345...",
          callData: "0x012345...",
          value: BigInt(0),
        },
      ],
    });
  };

  const handleAsyncSendPermission = async () => {
    try {
      const txHash = await sendPermissionAsync({
        actions: [
          {
            target: 0x012345...",
            callData: "0x012345...",
            value: BigInt(0),
          },
        ],
      });
<strong>      console.log("Transaction hash:", txHash);
</strong>    } catch (err) {
      console.error("Permission sending failed:", err);
    }
  };

  return (
    &#x3C;div>
      {isPending &#x26;&#x26; &#x3C;p>Sending permission...&#x3C;/p>}
      {isSuccess &#x26;&#x26; &#x3C;p>Permission sent successfully!&#x3C;/p>}
      {isError &#x26;&#x26; &#x3C;p>Error: {error?.message}&#x3C;/p>}
      &#x3C;button onClick={handleSendPermission}>Send Permission&#x3C;/button>
      &#x3C;button onClick={handleAsyncSendPermission}>Send Permission (Async)&#x3C;/button>
    &#x3C;/div>
  );
};
</code></pre>

## How It Works:

The hook relies on the smartAccountClient and sessionKeySigner to handle permission operations via the cometh/connect-sdk-4337. The mutation follows these steps:

1\. Initializes the session key signer using useSessionKeySigner.

2\. Verifies the required context and API key are available.

3\. Creates a sessionKeyClient using createSessionSmartAccountClient.

4\. Calls the usePermission method with the provided parameters.

5\. Waits for confirmation using waitForUserOperationReceipt.

6\. Returns the transaction hash of the operation.

## Example of Expected Response:

```
"0x123abc456def..."
```

## Error Handling:

If the mutation fails, the error object provides information about what went wrong, allowing you to display user-friendly error messages.

## Mutation Props (mutationProps):

You can pass optional mutation options through the mutationProps parameter. This allows you to customize aspects of the mutation, like retry mechanisms, onSuccess callbacks, and more.
