Hooks
Client Management Hooks
Hooks for managing and accessing the Solana client connection
These hooks allow you to access and manage the Solana client configured in your SolanaProvider
.
useSolanaClient
Get the current Solana client configured in the SolanaProvider
, including the rpc
and
rpcSubscriptions
connections.
Usage
Return Value
Advanced Example
Using the client to make custom RPC calls:
useUpdateSolanaClient
Update the current Solana client in the SolanaProvider
. This is useful for switching between
different networks or RPC endpoints.
Usage
Parameters
client
- The new Solana client to set
Advanced Example
Switching to a custom RPC endpoint with error handling:
Best Practices
Client Initialization
Initialize your client with appropriate configuration for your use case:
Network Switching
When implementing network switching, consider:
- Clear caches when switching networks to avoid stale data
- Update wallet connections if using wallet adapters
- Notify users of network changes
- Persist preferences in local storage
Troubleshooting
Client Not Available
If useSolanaClient
returns undefined, ensure:
- Your component is wrapped in
SolanaProvider
- The provider is properly initialized with a client
- You're not calling the hook during SSR (use
"use client"
directive)
RPC Connection Issues
When updating clients, handle connection failures gracefully: