useGrantPermission
This hook provides functionality to asynchronously grant permissions and monitor the status of the transaction.
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:
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:
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:
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.
Last updated