useSendPermission
This hook handles the process of sending permissions and monitors the transaction’s status.
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:
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:
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.
Last updated