Stellar Wallet Kit - Quick Integration
Building a Stellar Wallet Management System
Overview
Step 1: Install Dependencies
npm install @creit.tech/stellar-wallets-kitStep 2: Configure the Stellar Wallet Kit
import {
StellarWalletsKit,
WalletNetwork,
FREIGHTER_ID,
AlbedoModule,
FreighterModule,
} from "@creit.tech/stellar-wallets-kit";
/**
* Main configuration for Stellar Wallet Kit
* This kit supports multiple wallet types including Freighter and Albedo
* Configure for TESTNET during development and MAINNET for production
*/
export const kit: StellarWalletsKit = new StellarWalletsKit({
network: WalletNetwork.TESTNET,
selectedWalletId: FREIGHTER_ID,
modules: [new FreighterModule(), new AlbedoModule()],
});
/**
* Interface for transaction signing parameters
*/
interface signTransactionProps {
unsignedTransaction: string;
address: string;
}
/**
* Sign a Stellar transaction using the connected wallet
* This function handles the signing process and returns the signed transaction
*
* @param unsignedTransaction - The XDR string of the unsigned transaction
* @param address - The wallet address that will sign the transaction
* @returns Promise<string> - The signed transaction XDR
*/
export const signTransaction = async ({
unsignedTransaction,
address,
}: signTransactionProps): Promise<string> => {
const { signedTxXdr } = await kit.signTransaction(unsignedTransaction, {
address,
networkPassphrase: WalletNetwork.TESTNET,
});
return signedTxXdr;
};Step 3: Create the Wallet Context Provider
Step 4: Create the Wallet Hook
Step 5: Integrate the Provider in Your App
Step 6: Use the Wallet Hook in Components
Key Features and Benefits
State Persistence
Multi-Wallet Support
Error Handling
Type Safety
Context-Based Architecture
Configuration Options
Network Selection
Last updated
Was this helpful?