Creating a New Wallet Adapter for Titan Kit
This guide explains how to create and integrate a new wallet adapter into Titan Kit. We'll focus on the core implementation details.
Understanding the Wallet Architecture
Titan Kit's wallet system is built on a flexible architecture with the following key components:
BaseWallet: The abstract base class that all wallet types extend from
ExtensionWallet: For browser extension wallets
CosmosWallet: Specifically for Cosmos-based wallets
EthereumWallet: For Ethereum-compatible wallets
WCWallet: For WalletConnect integration
Creating a New Extension Wallet
Let's walk through the process of creating a new wallet adapter for a browser extension.
1. Define Wallet Constants
Create a constant.ts file to store wallet-specific information:
// constant.ts
export const ICON =
"data:image/svg+xml;base64,YOUR_BASE64_ENCODED_SVG_LOGO";
// Add any other constants specific to your wallet here2. Create Wallet Registry
Create a registry.ts file to define the wallet information:
3. Create Custom Wallet Implementation (Optional)
If your wallet requires custom methods beyond the base functionality, create a custom wallet class:
4. Create Main Entry Point
Create an index.ts file to export your wallet instance:
Mobile Wallet Support
For mobile wallets using WalletConnect, update your wallet registry:
Hardware Wallet Support
For hardware wallets, create a custom implementation:
Using Your New Wallet
After creating your wallet adapter, you can use it in your application:
Best Practices
Error Handling
Implement proper error handling for connection failures
Provide clear error messages for users
Handle network-specific errors appropriately
Security
Follow security best practices
Implement proper encryption for sensitive data
Validate all user inputs
Compatibility
Test with multiple chains
Ensure compatibility with different network types
Support both mainnet and testnet environments
User Experience
Provide clear feedback during operations
Handle edge cases gracefully
Implement proper loading states
Testing
Test all wallet operations thoroughly
Test with different network conditions
Test error scenarios and recovery