Comprehensive guide to using React hooks from the Abstraxn Wallet SDK
This document provides comprehensive usage examples for all hooks available in the Abstraxn Wallet SDK React library.

Table of Contents

  1. Connection & Status Hooks
  2. Authentication Hooks
  3. Transaction Hooks
  4. Contract Interaction Hooks
  5. MFA Hooks
  6. Wallet Policy Hooks
  7. Typed Signing
  8. External Wallet Client Hook
  9. Solana Hooks
  10. Complete Transaction Flow Example
  11. Notes

Connection & Status Hooks

useIsConnected()

Check if the wallet is currently connected.
Returns: boolean - true if wallet is connected, false otherwise.

useAddress()

Get the current wallet address.
Returns: string | null - The wallet address or null if not connected.

useChainId()

Get the current chain ID.
Returns: number | null - The chain ID or null if not connected.

useError()

Get the current error state.
Returns: Error | null - The current error or null if no error.

useWallet()

Get the wallet instance for advanced usage.
Returns: Wallet instance or null if not connected.

useConnectionType()

Get the connection type (how the user connected).
Returns:
  • connectionType: ConnectorType | null - The connection method (‘google’, ‘x’, ‘discord’, ‘metamask’, ‘walletconnect’, ‘email’, ‘passkey’, etc.)
  • connectorMeta: Connector metadata with name, icon, etc.

Authentication Hooks

useAuthContext()

Get current user and whoami information.
Returns:
  • user: User object
  • whoami: Whoami response with address information

useWhoami()

Call whoami API with loading state and refresh capability.
Returns:
  • whoami: WhoamiResponse | null - Whoami data
  • loading: boolean - Loading state
  • error: Error | null - Error state
  • refreshWhoami: Function to refresh whoami data
  • isConnected: boolean - Connection status

useExportWallet()

Export wallet private key.
Returns:
  • exportWallet: Function to export wallet
  • isConnected: boolean - Connection status
  • address: string | null - Wallet address

Transaction Hooks

usePublicClient(chain, rpcUrl)

Create a publicClient using viem for read operations.
Parameters:
  • chain: Viem chain object (from ‘viem/chains’ or custom)
  • rpcUrl: RPC URL for the chain
Returns:
  • publicClient: PublicClient instance from viem

useWalletClient(chain, rpcUrl?)

Create a walletClient using viem for broadcasting signed transactions.
Parameters:
  • chain: Viem chain object
  • rpcUrl: Optional RPC URL (uses chain’s default if not provided)
Returns:
  • walletClient: WalletClient instance from viem

usePrepareRawTxn(provider)

Prepare raw transaction data with encoding support.
Parameters:
  • provider: PublicClient instance
Returns:
  • prepareRawTxn: Function that accepts:
    • from: Address
    • to: Address
    • value?: Native token value (pass in chain/base units, e.g. wei)
    • data?: Pre-encoded function data
    • abi?: Contract ABI (for encoding)
    • functionName?: Function name (for encoding)
    • args?: Function arguments (passed through as-is; no implicit amount conversion)

useSignTxn(provider)

Sign transaction using Abstraxn server wallet API.
Parameters:
  • provider: PublicClient instance
Returns:
  • signTxn: Function to sign transaction
  • isConnected: boolean - Connection status
  • address: string | null - Wallet address

useSignAndSendTxn(provider)

Sign and send transaction using Abstraxn server wallet API.
Parameters:
  • provider: PublicClient instance
Returns:
  • signAndSendTxn: Function to sign and send transaction
  • isConnected: boolean - Connection status
  • address: string | null - Wallet address

useWaitForTxnReceipt(provider)

Wait for transaction receipt.
Parameters:
  • provider: PublicClient instance
Returns:
  • waitForTxnReceipt: Function that accepts:
    • hash: Transaction hash
    • confirmations?: Number of confirmations to wait for
    • timeout?: Timeout in milliseconds

useSwitchChain()

Switch chain for both internal (social) and external wallets.
Returns:
  • switchChain: Function to switch chain (accepts chainId: number)

useSignMessage()

Sign a message (for external wallets only).
Note: Signing messages is not supported for embedded wallets (Google, email, etc.). Only works with external wallets.
Returns:
  • signMessage: Function to sign message (accepts message: string)

Contract Interaction Hooks

useContract({ address, abi, provider })

Create a contract instance using viem.
Parameters:
  • address: Contract address
  • abi: Contract ABI
  • provider: PublicClient instance
Returns:
  • contract: Contract instance from viem

useReadContract(provider)

Read from contract using publicClient.
Parameters:
  • provider: PublicClient instance
Returns:
  • readContract: Function that accepts:
    • address: Contract address
    • abi: Contract ABI
    • functionName: Function name
    • args?: Function arguments

useWriteContract()

Write to contract (for external wallets like MetaMask, WalletConnect, etc.).
Returns:
  • writeContract: Function that accepts:
    • address: Contract address
    • abi: Contract ABI
    • functionName: Function name
    • args?: Function arguments
    • value?: ETH value (bigint)
    • account?: Account address
    • gas?: Gas limit
    • gasPrice?: Gas price
    • maxFeePerGas?: Max fee per gas
    • maxPriorityFeePerGas?: Max priority fee per gas
    • nonce?: Nonce

MFA Hooks

useEnableMfa()

Manage the MFA enable setup flow:
  • start() initializes setup and returns QR + secret
  • verifyCode(code) verifies TOTP setup
  • verifyRecoveryCode(code) validates backup/recovery code
  • setupState moves through setup -> verify -> complete

useDisableMfa()

Manage MFA disable flow:
  • start() begins auth step
  • switchMethod('otp' | 'recovery') selects auth mode
  • verifyCode(code) verifies OTP or backup code
  • confirmDisable() disables MFA after verification

useEmailForOtp()

Pre-fill the onboarding email field for OTP login.

Wallet Policy Hooks

Temporarily unavailable. Wallet policies are disabled on wallet-service while we finalize secure-enclave enforcement. Do not ship policy UI or SDK createPolicy flows to production yet. See Wallet policies for status.
The hooks below are implemented in @abstraxn/signer-react but the live API returns 503 until the feature is re-enabled.

useCreatePolicy() / usePolicies()

Other policy hooks: usePolicy(id), useUpdatePolicy(), useDeletePolicy(), usePublishPolicy(), useUnpublishPolicy(), usePolicyTemplates().

Typed Signing

useSignTypedTx()

Sign EIP-712 payloads with embedded wallets.

External Wallet Client Hook

useExternalWalletClient()

Access the underlying external wallet client (wagmi connector client) and connection state.

Solana Hooks

useSolanaConnection(rpcUrl, commitment?)

Create a Solana RPC connection.

useSolanaPublicKey()

Get the current Solana address from authenticated user context.

useSolanaBalance()

Load Solana balance (lamports, formattedBalance, loading/error).

usePrepareSolanaTxn(connection)

Prepare transfer or instruction-based transactions.

useSignSolanaTxn(connection)

Sign prepared Solana transaction through SDK signing API.

useSignAndSendSolanaTxn(connection)

Sign and send prepared Solana transaction in one call.

useWaitForSolanaConfirmation(connection)

Wait for signature confirmation on Solana.

usePrepareSolanaProgramTxn(connection) and useSolanaProgramTransaction(connection)

Prepare and send program transactions with programId, accounts, and encoded instruction data.

useSolanaExternalWallet()

Interact with connected external Solana wallets (sign message, sign tx, send tx).

Complete Transaction Flow Example

Here’s a complete example showing how to use multiple hooks together for a full transaction flow:

Notes

  1. Provider Setup: Most hooks require a PublicClient instance. Create it using usePublicClient(chain, rpcUrl).
  2. Connection Types:
    • Social logins (Google, email, X, Discord, passkey) use embedded wallets
    • External wallets (MetaMask, WalletConnect) use the connected wallet directly
  3. Transaction Flow:
    • For embedded wallets: Use usePrepareRawTxnuseSignAndSendTxnuseWaitForTxnReceipt
    • For external wallets: Use useWriteContract or useExternalWalletInfo().walletClient
  4. Error Handling: Always wrap hook calls in try-catch blocks for proper error handling.
  5. Loading States: Many hooks provide loading states. Use them to show loading indicators in your UI.
  6. Chain Switching: Use useSwitchChain() to switch chains. It works for both embedded and external wallets.
  7. MFA Step-Up: Signing hooks may require an MFA step-up verification code when enhanced security is enabled.

Next Steps

  • Learn about App Integration - Integrate hooks into your application
  • Explore UI Customization - Customize the wallet UI
  • Configure MFA - Enable or disable two-factor flows
  • Build with Solana - Embedded and external Solana wallets
  • Wallet policies — temporarily unavailable (status)
  • Check out Dashboard customization - Configure authentication methods