API Reference
Complete documentation for all XRPL-Connect APIs.
WalletManager
The central API for managing wallet connections and signing transactions.
Constructor
const walletManager = new WalletManager(options: WalletManagerConfig)Config Options
| Property | Type | Description |
|---|---|---|
adapters | WalletAdapter[] | Array of wallet adapters |
network | 'mainnet' | 'testnet' | 'devnet' | XRPL network to connect to |
autoConnect | boolean | Auto-reconnect on initialization |
logger | Logger | Logger instance for debugging |
Properties
| Property | Type | Description |
|---|---|---|
connected | boolean | Whether a wallet is currently connected |
account | Account | null | Currently connected account |
wallet | Wallet | null | Currently connected wallet |
adapters | WalletAdapter[] | List of available adapters |
Methods
signAndSubmit()
async signAndSubmit(transaction: Transaction): Promise<SubmitResult>Sign and submit a transaction to the ledger.
signMessage()
async signMessage(message: string): Promise<SignResult>Sign a message using the connected wallet.
disconnect()
async disconnect(): Promise<void>Disconnect the current wallet and clear stored session.
on()
on(event: string, listener: Function): voidListen to wallet events.
off()
off(event: string, listener: Function): voidRemove event listener.
once()
once(event: string, listener: Function): voidListen to event once, then remove listener.
Web Component: xrpl-wallet-connector
Beautiful UI component for wallet connection.
Usage
<xrpl-wallet-connector
id="wallet-connector"
style="
--xc-background-color: #1a202c;
--xc-primary-color: #3b99fc;
"
primary-wallet="xaman"
wallets="xaman,crossmark,walletconnect"
></xrpl-wallet-connector>Attributes
| Attribute | Type | Description |
|---|---|---|
primary-wallet | string | Wallet ID to feature/highlight |
wallets | string | Comma-separated list of wallet IDs |
Methods
setWalletManager()
setWalletManager(walletManager: WalletManager): voidConnect the component to a WalletManager instance.
open()
async open(): Promise<void>Open the wallet selection modal.
close()
close(): voidClose any open modals.
Events
connecting
Emitted when connecting to a wallet.
connector.addEventListener('connecting', (e) => {
console.log('Connecting to:', e.detail.walletId);
});connected
Emitted when successfully connected.
connector.addEventListener('connected', (e) => {
console.log('Connected:', e.detail);
});error
Emitted when connection fails.
connector.addEventListener('error', (e) => {
console.error('Error:', e.detail.error.message);
});Wallet Adapters
Built-in adapters for popular XRPL wallets.
Xaman Adapter
import { XamanAdapter } from 'xrpl-connect';
const adapter = new XamanAdapter({
apiKey: 'YOUR_API_KEY', // Get from https://apps.xumm.dev/
apiSecret: 'YOUR_API_SECRET', // Optional
});Supported Features: Transaction signing, message signing, QR codes
Get API Key: https://apps.xumm.dev/
Crossmark Adapter
import { CrossmarkAdapter } from 'xrpl-connect';
const adapter = new CrossmarkAdapter();Supported Features: Transaction signing, message signing
Website: https://crossmark.io/
GemWallet Adapter
import { GemWalletAdapter } from 'xrpl-connect';
const adapter = new GemWalletAdapter();Supported Features: Transaction signing, message signing
Website: https://gemwallet.com/
WalletConnect Adapter
import { WalletConnectAdapter } from 'xrpl-connect';
const adapter = new WalletConnectAdapter({
projectId: 'YOUR_PROJECT_ID', // Get from https://cloud.walletconnect.com
});Supported Features: Transaction signing, message signing, mobile wallets
Get Project ID: https://cloud.walletconnect.com/
Types & Interfaces
Account
interface Account {
address: string;
network: Network;
}Network
interface Network {
id: string;
name: string;
rpcUrl?: string;
}Transaction
interface Transaction {
TransactionType: string;
Account: string;
[key: string]: any;
}SubmitResult
interface SubmitResult {
hash?: string;
tx_blob?: string;
[key: string]: any;
}SignResult
interface SignResult {
message: string;
signature: string;
}WalletError
interface WalletError extends Error {
code: string;
details?: any;
}Events
WalletManager Events
connect
Emitted when a wallet is connected.
walletManager.on('connect', (account: Account) => {
console.log('Connected:', account.address);
});disconnect
Emitted when a wallet is disconnected.
walletManager.on('disconnect', () => {
console.log('Disconnected');
});error
Emitted when an error occurs.
walletManager.on('error', (error: WalletError) => {
console.error('Error:', error.message);
});accountChange
Emitted when the connected account changes.
walletManager.on('accountChange', (account: Account) => {
console.log('Account changed:', account.address);
});networkChange
Emitted when the network changes.
walletManager.on('networkChange', (network: Network) => {
console.log('Network changed:', network.name);
});Error Handling
Error Codes
| Code | Description | Handling |
|---|---|---|
WALLET_NOT_FOUND | Wallet is not installed or not available | Notify user to install wallet |
CONNECTION_FAILED | Failed to connect to wallet | Retry connection or try different wallet |
SIGN_FAILED | Failed to sign transaction | User rejected or wallet error |
INVALID_PARAMS | Invalid transaction parameters | Check transaction format |
NETWORK_ERROR | Network communication failed | Check connection and retry |
Error Example
try {
const result = await walletManager.signAndSubmit(transaction);
} catch (error) {
if (error instanceof WalletError) {
switch (error.code) {
case 'WALLET_NOT_FOUND':
console.log('Please install a wallet');
break;
case 'SIGN_FAILED':
console.log('Transaction was rejected');
break;
default:
console.error('Unexpected error:', error.message);
}
}
}