Comprehensive guide to using React hooks from the Abstraxn Wallet SDKThis document provides comprehensive usage examples for all hooks available in the Abstraxn Wallet SDK React library.
Table of Contents
- Connection & Status Hooks
- Authentication Hooks
- Transaction Hooks
- Contract Interaction Hooks
- MFA Hooks
- Wallet Policy Hooks
- Typed Signing
- External Wallet Client Hook
- Solana Hooks
- Complete Transaction Flow Example
- Notes
Connection & Status Hooks
useIsConnected()
Check if the wallet is currently connected.
boolean - true if wallet is connected, false otherwise.
useAddress()
Get the current wallet address.
string | null - The wallet address or null if not connected.
useChainId()
Get the current chain ID.
number | null - The chain ID or null if not connected.
useError()
Get the current error state.
Error | null - The current error or null if no error.
useWallet()
Get the wallet instance for advanced usage.
null if not connected.
useConnectionType()
Get the connection type (how the user connected).
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.
user: User objectwhoami: Whoami response with address information
useWhoami()
Call whoami API with loading state and refresh capability.
whoami:WhoamiResponse | null- Whoami dataloading:boolean- Loading stateerror:Error | null- Error staterefreshWhoami: Function to refresh whoami dataisConnected:boolean- Connection status
useExportWallet()
Export wallet private key.
exportWallet: Function to export walletisConnected:boolean- Connection statusaddress:string | null- Wallet address
Transaction Hooks
usePublicClient(chain, rpcUrl)
Create a publicClient using viem for read operations.
chain: Viem chain object (from ‘viem/chains’ or custom)rpcUrl: RPC URL for the chain
publicClient: PublicClient instance from viem
useWalletClient(chain, rpcUrl?)
Create a walletClient using viem for broadcasting signed transactions.
chain: Viem chain objectrpcUrl: Optional RPC URL (uses chain’s default if not provided)
walletClient: WalletClient instance from viem
usePrepareRawTxn(provider)
Prepare raw transaction data with encoding support.
provider: PublicClient instance
prepareRawTxn: Function that accepts:from: Addressto: Addressvalue?: Native token value (pass in chain/base units, e.g. wei)data?: Pre-encoded function dataabi?: 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.
provider: PublicClient instance
signTxn: Function to sign transactionisConnected:boolean- Connection statusaddress:string | null- Wallet address
useSignAndSendTxn(provider)
Sign and send transaction using Abstraxn server wallet API.
provider: PublicClient instance
signAndSendTxn: Function to sign and send transactionisConnected:boolean- Connection statusaddress:string | null- Wallet address
useWaitForTxnReceipt(provider)
Wait for transaction receipt.
provider: PublicClient instance
waitForTxnReceipt: Function that accepts:hash: Transaction hashconfirmations?: Number of confirmations to wait fortimeout?: Timeout in milliseconds
useSwitchChain()
Switch chain for both internal (social) and external wallets.
switchChain: Function to switch chain (acceptschainId: number)
useSignMessage()
Sign a message (for external wallets only).
signMessage: Function to sign message (acceptsmessage: string)
Contract Interaction Hooks
useContract({ address, abi, provider })
Create a contract instance using viem.
address: Contract addressabi: Contract ABIprovider: PublicClient instance
contract: Contract instance from viem
useReadContract(provider)
Read from contract using publicClient.
provider: PublicClient instance
readContract: Function that accepts:address: Contract addressabi: Contract ABIfunctionName: Function nameargs?: Function arguments
useWriteContract()
Write to contract (for external wallets like MetaMask, WalletConnect, etc.).
writeContract: Function that accepts:address: Contract addressabi: Contract ABIfunctionName: Function nameargs?: Function argumentsvalue?: ETH value (bigint)account?: Account addressgas?: Gas limitgasPrice?: Gas pricemaxFeePerGas?: Max fee per gasmaxPriorityFeePerGas?: Max priority fee per gasnonce?: Nonce
MFA Hooks
useEnableMfa()
Manage the MFA enable setup flow:
start()initializes setup and returns QR + secretverifyCode(code)verifies TOTP setupverifyRecoveryCode(code)validates backup/recovery codesetupStatemoves throughsetup->verify->complete
useDisableMfa()
Manage MFA disable flow:
start()begins auth stepswitchMethod('otp' | 'recovery')selects auth modeverifyCode(code)verifies OTP or backup codeconfirmDisable()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.@abstraxn/signer-react but the live API returns 503 until the feature is re-enabled.
useCreatePolicy() / usePolicies()
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
-
Provider Setup: Most hooks require a
PublicClientinstance. Create it usingusePublicClient(chain, rpcUrl). -
Connection Types:
- Social logins (Google, email, X, Discord, passkey) use embedded wallets
- External wallets (MetaMask, WalletConnect) use the connected wallet directly
-
Transaction Flow:
- For embedded wallets: Use
usePrepareRawTxn→useSignAndSendTxn→useWaitForTxnReceipt - For external wallets: Use
useWriteContractoruseExternalWalletInfo().walletClient
- For embedded wallets: Use
- Error Handling: Always wrap hook calls in try-catch blocks for proper error handling.
- Loading States: Many hooks provide loading states. Use them to show loading indicators in your UI.
-
Chain Switching: Use
useSwitchChain()to switch chains. It works for both embedded and external wallets. - 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