Connect 4337
Cometh ConnectCometh MarketplaceCometh Checkout
  • 🚀Quick start
    • What is Connect 4337
    • Getting started
    • Supported Networks
  • 🛠️CORE FEATURES
    • Create a Wallet
    • Send transactions
    • Go Gasless
    • Sign/Verify a message
    • Retrieve a wallet address
    • Handle owners
    • Import a safe into connect
  • 🥷ADVANCED
    • Session Keys
      • Tutorial
      • Policies
        • Sudo policy
        • Action policy
    • Social recovery
    • Add a passkey signer on a different OS
    • Capabilities
      • sendCalls
      • getCallsStatus
      • getCapabilities
      • grantPermissions
    • Other signers (Auth Providers)
      • EOA wallets (Metamask, Phantom...)
      • Magic signer
      • Web3Auth signer
      • Turnkey signer
      • Privy signer
  • 🔌Integrations
    • React hooks
      • ConnectProvider
      • useAccount
      • useConnect
      • useDisconnect
      • useGetGasPrice
      • useSendTransaction
      • useSignMessage
      • useVerifyMessage
      • useWriteContract
      • Handle owners
        • useRemoveOwner
        • useValidateAddDevice
        • useCreateNewSigner
        • useAddOwner
        • useGetOwners/EnrichedOwners
      • Session Keys
        • useGrantPermission
        • useSendPermission
        • useSessionKeyClient
        • useSessionKeySigner
      • Recovery
        • useIsRecoveryActive
        • useSetUpRecovery
        • useGetRecoveryRequest
        • useCancelRecoveryRequest
    • Mobile SDKs
      • IOS
      • Android
      • React Native
    • Wagmi
  • SDK Core
    • Signers (Auth Providers)
      • EOA wallets (Metamask, Phantom...)
      • Magic signer
      • Web3Auth signer
      • Turnkey signer
      • Privy signer
    • Handle owners
    • Capabilities
      • sendCalls
      • getCallsStatus
      • getCapabilities
  • SDK Session Keys
    • Setup Smart Account Client
    • Manage session keys
    • Policies
      • Sudo policy
      • Action policy
  • 📦Bundler
    • Bundler API
      • eth_sendUserOperation
      • eth_estimateUserOperationGas
      • eth_getUserOperationByHash
      • eth_getUserOperationReceipt
      • eth_supportedEntryPoints
  • 💳Paymaster
    • Paymaster API
  • 📖RESOURCES
    • Migrate from the connect legacy SDK
    • Connect Legacy SDKs (Unity, JS)
    • FAQ
Powered by GitBook
On this page
  • Returns:
  • Usage Example:
  • How It Works:
  • Example of Expected Response:
  • Error Handling:
  • Mutation Props (mutationProps):
  1. Integrations
  2. React hooks
  3. Session Keys

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:

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),
          },
        ],
      });
      console.log("Transaction hash:", txHash);
    } catch (err) {
      console.error("Permission sending failed:", err);
    }
  };

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

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.

PrevioususeGrantPermissionNextuseSessionKeyClient

Last updated 3 months ago

🔌