useSolanaWallet
Defined in: account-kit/react/dist/types/hooks/useSolanaWallet.d.ts:48
A React hook that mirrors the behavior and return type of
useWallet from @solana/wallet-adapter-react, but safely degrades when
Solana is not enabled for your application.
Context:
- This repository is an external SDK that supports multiple chains. To avoid
forcing Solana dependencies on apps that do not use Solana, the Solana
wallet context is only considered “active” if Solana has been initialized
in the
AlchemyAccountProviderconfiguration. - If Solana is not initialized, this hook returns a stable, frozen
EMPTY_WALLET_CONTEXT_STATEinstead of reading fromWalletContext. This prevents runtime errors when the Solana provider is not present and keeps type-safe parity withuseWalletconsumers.
Behavior:
- When Solana is configured (i.e. adapters are provided or set to “detect”),
this hook returns the live
WalletContextfrom@solana/wallet-adapter-react. - Otherwise, it returns
EMPTY_WALLET_CONTEXT_STATEwhere actions such assignMessage,sendTransaction, etc., will reject with “Solana wallet not available”.
Example
import { function useSolanaWallet(): WalletContextStateA React hook that mirrors the behavior and return type of useWallet from @solana/wallet-adapter-react, but safely degrades when Solana is not enabled for your application.
Context:
This repository is an external SDK that supports multiple chains. To avoid forcing Solana dependencies on apps that do not use Solana, the Solana wallet context is only considered "active" if Solana has been initialized in the AlchemyAccountProvider configuration.
If Solana is not initialized, this hook returns a stable, frozen EMPTY_WALLET_CONTEXT_STATE instead of reading from WalletContext. This prevents runtime errors when the Solana provider is not present and keeps type-safe parity with useWallet consumers.
Behavior:
When Solana is configured (i.e. adapters are provided or set to "detect"), this hook returns the live WalletContext from @solana/wallet-adapter-react.
Otherwise, it returns EMPTY_WALLET_CONTEXT_STATE where actions such as signMessage, sendTransaction, etc., will reject with "Solana wallet not available".
useSolanaWallet } from "@account-kit/react";
const const wallet: WalletContextStatewallet = function useSolanaWallet(): WalletContextStateA React hook that mirrors the behavior and return type of useWallet from @solana/wallet-adapter-react, but safely degrades when Solana is not enabled for your application.
Context:
This repository is an external SDK that supports multiple chains. To avoid forcing Solana dependencies on apps that do not use Solana, the Solana wallet context is only considered "active" if Solana has been initialized in the AlchemyAccountProvider configuration.
If Solana is not initialized, this hook returns a stable, frozen EMPTY_WALLET_CONTEXT_STATE instead of reading from WalletContext. This prevents runtime errors when the Solana provider is not present and keeps type-safe parity with useWallet consumers.
Behavior:
When Solana is configured (i.e. adapters are provided or set to "detect"), this hook returns the live WalletContext from @solana/wallet-adapter-react.
Otherwise, it returns EMPTY_WALLET_CONTEXT_STATE where actions such as signMessage, sendTransaction, etc., will reject with "Solana wallet not available".
useSolanaWallet();
if (const wallet: WalletContextStatewallet.WalletContextState.connected: booleanconnected) {
// Safe to use wallet.publicKey, sendTransaction, etc.
} else {
// Solana not configured or not connected; UI can conditionally render.
}Returns
WalletContextState
The Solana wallet context when enabled; a frozen, safe no-op context when Solana is not configured.