A multi-wallet connection library for Stellar dApps. Drop-in React hooks, a ready-to-use <WalletButton />, and a clean adapter interface for adding new wallets.
- Multi-wallet adapters — Freighter supported out of the box; extend with any wallet via the
WalletAdapterinterface <WalletButton />— one component handles connect, disconnect, address display, and balance<WalletModal />— wallet selection modal with installed/not-installed state<NetworkBadge />— coloured badge showing current network (Mainnet/Testnet/Futurenet)useWallet— full wallet context: address, status, connect, disconnect, signuseBalance— live XLM + asset balances from Horizon with auto-refreshuseNetwork— current network withisTestnet,isMainnethelpersuseStellarTx— build, sign, and submit payment transactions in one hook- Auto-reconnect — restores last session on page reload
- TypeScript-first — full type coverage
npm install stellar-connectWrap your app in <StellarConnectProvider> and drop in <WalletButton />:
import { StellarConnectProvider, WalletButton } from 'stellar-connect';
export default function App() {
return (
<StellarConnectProvider>
<WalletButton />
</StellarConnectProvider>
);
}const {
address, // string | null
status, // 'idle' | 'connecting' | 'connected' | 'error'
network, // 'TESTNET' | 'MAINNET' | ...
connect, // (adapterId?: string) => Promise<void>
disconnect, // () => void
signTransaction, // (xdr, network?) => Promise<string>
signMessage, // (message) => Promise<string>
} = useWallet();const { xlmBalance, allBalances, isLoading, error, refresh } = useBalance(
address,
'TESTNET',
30_000, // auto-refresh every 30s
);const { network, isTestnet, isMainnet, isNetwork } = useNetwork();const { sendPayment, signAndSubmit, status, txResult, error, reset } = useStellarTx();
// Send a payment
await sendPayment({
destination: 'G...',
amount: '10',
memo: 'thanks',
});
// Or sign and submit a pre-built XDR
await signAndSubmit(xdrString);<WalletButton label="Connect Wallet" className="my-btn" /><WalletModal open={isOpen} onClose={() => setOpen(false)} /><NetworkBadge /> // renders "TESTNET" / "MAINNET" badgeImplement WalletAdapter to add any Stellar wallet:
import type { WalletAdapter } from 'stellar-connect';
export const myWalletAdapter: WalletAdapter = {
id: 'my-wallet',
name: 'My Wallet',
icon: 'https://...',
downloadUrl: 'https://...',
async isInstalled() { ... },
async connect() { ... },
async getAddress() { ... },
async getNetwork() { ... },
async signTransaction(xdr, network) { ... },
async signMessage(message) { ... },
watch(onChange) { ...; return () => {}; },
async descriptor() { ... },
};Then register it:
<StellarConnectProvider adapters={[freighterAdapter, myWalletAdapter]}>
...
</StellarConnectProvider>import { truncateAddress, txExplorerUrl, isValidStellarAddress } from 'stellar-connect';
truncateAddress('GABC...XYZ') // 'GABC…XYZ'
txExplorerUrl(hash, 'TESTNET') // Stellar Expert link
isValidStellarAddress('G...') // booleansrc/
├── adapters/
│ ├── base.ts # WalletAdapter interface
│ └── freighter.ts # Freighter implementation
├── context/
│ └── WalletContext.tsx # StellarConnectProvider
├── hooks/
│ ├── useWallet.ts
│ ├── useBalance.ts
│ ├── useNetwork.ts
│ └── useStellarTx.ts
├── components/
│ ├── WalletButton.tsx
│ ├── WalletModal.tsx
│ └── NetworkBadge.tsx
├── utils/
│ ├── address.ts
│ └── network.ts
├── types.ts
└── index.ts
MIT