Wallet Integration
Nester uses StellarWalletsKit to support multiple Stellar wallets via a unified adapter.
Setup
bash
npm install @creit.tech/stellar-wallets-kit @stellar/stellar-sdkProvider Implementation
typescript
import { StellarWalletsKit } from "@creit.tech/stellar-wallets-kit";
import { defaultModules } from "@creit.tech/stellar-wallets-kit/modules/utils";
// Initialize kit with all default wallet modules
const kit = new StellarWalletsKit({
network: "TESTNET",
selectedWalletId: "freighter",
modules: defaultModules(),
});
// Supported wallets (via defaultModules):
// Freighter, Lobstr, xBull, Hana, Rabet, Albedo,
// WalletConnect, XDEFI, Hot WalletConnection Flow
typescript
async function connectWallet(walletId: string) {
// 1. Set the active wallet
kit.setWallet(walletId);
// 2. Get address from the wallet extension directly
const module = kit.selectedModule;
const { address } = await module.getAddress();
// 3. Sync the kit's internal state
const { activeAddress } = await import(
"@creit.tech/stellar-wallets-kit/state"
);
activeAddress.value = address;
// 4. Store session for persistence
localStorage.setItem("nester_wallet_id", walletId);
localStorage.setItem("nester_wallet_addr", address);
return address;
}Important: Callkit.selectedModule.getAddress(), NOTkit.getAddress(). The latter only reads from memory and will throw "No wallet connected" ifactiveAddresshasn't been set.
Handling Uninstalled Wallets
typescript
const INSTALL_URLS: Record<string, string> = {
freighter: "https://chromewebstore.google.com/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk",
lobstr: "https://chromewebstore.google.com/detail/lobstr-signer/ldiagbjmlmfagcjpbbkobgjgkihfkiab",
xbull: "https://chromewebstore.google.com/detail/xbull-wallet/omajpeaffjgmlpmhbfdmmaplefklipcb",
// ... more wallets
};
async function connect(walletId: string) {
try {
return await connectWallet(walletId);
} catch (error) {
// Wallet not installed — redirect to Chrome Web Store
const installUrl = INSTALL_URLS[walletId];
if (installUrl) {
window.open(installUrl, "_blank");
}
}
}