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:
  • Error Handling:
  • Customization:
  1. Integrations
  2. React hooks
  3. Session Keys

useSessionKeySigner

This hook returns a session key signer based on the provided session data and private key. The signer is used to interact with smart sessions and execute permissioned actions.

Returns:

Property

Type

Description

data

SafeSigner<"safeSmartSessionsSigner"> or undefined

The session key signer if it was successfully created, otherwise undefined.

error

Error or null

An error object if the signer creation failed, otherwise null.

isPending

boolean

A boolean indicating whether the signer is currently being created.

isSuccess

boolean

A boolean indicating whether the session key signer was successfully created.

isError

boolean

A boolean indicating whether an error occurred during the signer creation.

Usage Example:

import { useSessionKeySigner } from "path/to/hook";

const Component = () => {
  const { data: sessionKeySigner, error, isPending, isSuccess, isError } =
    useSessionKeySigner({
      sessionData: { permissionIds: [...], action: "...", sessions: [...] },
      privateKey: "0xYOUR_PRIVATE_KEY",
    });

  if (isPending) return <p>Initializing session key signer...</p>;
  if (isError) return <p>Error: {error?.message}</p>;

  return (
    <div>
      {isSuccess && <p>Session Key Signer Initialized!</p>}
      <button
        onClick={() => {
          if (sessionKeySigner) {
            // Example usage: signing an operation
            console.log("Session Key Signer:", sessionKeySigner);
          }
        }}
      >
        Use Session Key Signer
      </button>
    </div>
  );
};

How It Works:

The hook follows these steps to create the session key signer:

1. Uses the smartAccountClient obtained from useSmartAccount.

2. Extends the client using smartSessionActions and erc7579Actions.

3. Converts the smart account into a session signer using the toSmartSessionsSigner utility.

4. Returns the signer, which can then be used to sign permissioned operations.

Example of Expected Response:

{
  "type": "safeSmartSessionsSigner",
  "signer": "Signer instance with session capabilities"
}

Error Handling:

If an error occurs during the creation of the session key signer, the error object will provide information about what went wrong. This can be used to display helpful error messages to the user.

Customization:

The query is controlled using wagmi’s useQuery. You can pass additional options (e.g., enabling/disabling the query dynamically) as needed.

PrevioususeSessionKeyClientNextRecovery

Last updated 3 months ago

🔌