stellar-wallet-kit 2.0.0 β 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -424
- package/dist/index.d.mts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +357 -239
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +357 -239
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
# π Stellar Wallet Kit
|
|
2
2
|
|
|
3
|
-
A comprehensive, production-ready wallet connection
|
|
3
|
+
A comprehensive, production-ready wallet connection SDK for Stellar dApps.
|
|
4
|
+
Built with TypeScript and React, inspired by RainbowKit.
|
|
4
5
|
|
|
5
6
|
[](https://www.npmjs.com/package/stellar-wallet-kit)
|
|
6
7
|
[](https://opensource.org/licenses/MIT)
|
|
7
8
|
[](https://www.typescriptlang.org/)
|
|
8
9
|
|
|
10
|
+
---
|
|
11
|
+
|
|
9
12
|
## β¨ Features
|
|
10
13
|
|
|
11
|
-
- π **Multiple Wallet Support**
|
|
12
|
-
- π¨ **Fully Customizable**
|
|
13
|
-
- β‘ **TypeScript First**
|
|
14
|
-
- π― **React Hooks**
|
|
15
|
-
- π° **Built-in Balance
|
|
16
|
-
- πΎ **Auto-reconnect**
|
|
17
|
-
- π **
|
|
18
|
-
- π **Auto-refresh
|
|
19
|
-
- π **
|
|
20
|
-
- π± **Next.js
|
|
21
|
-
- πͺ **
|
|
14
|
+
- π **Multiple Wallet Support** β Freighter & Albedo
|
|
15
|
+
- π¨ **Fully Customizable UI** β Theme control to match your brand
|
|
16
|
+
- β‘ **TypeScript First** β Full type safety & IntelliSense
|
|
17
|
+
- π― **React Hooks API** β Simple `useWallet()` hook
|
|
18
|
+
- π° **Built-in Balance Fetching**
|
|
19
|
+
- πΎ **Auto-reconnect** (extension wallets)
|
|
20
|
+
- π **Light / Dark / Auto theme**
|
|
21
|
+
- π **Auto-refresh balances**
|
|
22
|
+
- π **Framework-agnostic SDK**
|
|
23
|
+
- π± **Next.js compatible**
|
|
24
|
+
- πͺ **Beautiful Wallet Modal**
|
|
25
|
+
|
|
26
|
+
---
|
|
22
27
|
|
|
23
28
|
## π¦ Installation
|
|
24
29
|
|
|
@@ -28,16 +33,18 @@ npm install stellar-wallet-kit
|
|
|
28
33
|
yarn add stellar-wallet-kit
|
|
29
34
|
# or
|
|
30
35
|
pnpm add stellar-wallet-kit
|
|
31
|
-
|
|
36
|
+
````
|
|
37
|
+
|
|
38
|
+
---
|
|
32
39
|
|
|
33
40
|
## π Quick Start
|
|
34
41
|
|
|
35
|
-
### 1
|
|
42
|
+
### 1οΈβ£ Wrap your app with `WalletProvider`
|
|
36
43
|
|
|
37
44
|
```tsx
|
|
38
45
|
import { WalletProvider, NetworkType } from 'stellar-wallet-kit';
|
|
39
46
|
|
|
40
|
-
function App() {
|
|
47
|
+
export function App() {
|
|
41
48
|
return (
|
|
42
49
|
<WalletProvider
|
|
43
50
|
config={{
|
|
@@ -51,22 +58,21 @@ function App() {
|
|
|
51
58
|
}
|
|
52
59
|
```
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### 2οΈβ£ Add the Connect Button
|
|
55
64
|
|
|
56
65
|
```tsx
|
|
57
66
|
import { ConnectButton } from 'stellar-wallet-kit';
|
|
58
67
|
|
|
59
|
-
function Header() {
|
|
60
|
-
return
|
|
61
|
-
<header>
|
|
62
|
-
<h1>My Stellar dApp</h1>
|
|
63
|
-
<ConnectButton showBalance />
|
|
64
|
-
</header>
|
|
65
|
-
);
|
|
68
|
+
export function Header() {
|
|
69
|
+
return <ConnectButton showBalance />;
|
|
66
70
|
}
|
|
67
71
|
```
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### 3οΈβ£ Use the `useWallet()` hook
|
|
70
76
|
|
|
71
77
|
```tsx
|
|
72
78
|
import { useWallet } from 'stellar-wallet-kit';
|
|
@@ -89,500 +95,264 @@ function Dashboard() {
|
|
|
89
95
|
}
|
|
90
96
|
```
|
|
91
97
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
### Theme Configuration
|
|
95
|
-
|
|
96
|
-
```tsx
|
|
97
|
-
<WalletProvider
|
|
98
|
-
config={{
|
|
99
|
-
network: NetworkType.TESTNET,
|
|
100
|
-
appName: "My Stellar dApp",
|
|
101
|
-
appIcon: "https://myapp.com/icon.png",
|
|
102
|
-
theme: {
|
|
103
|
-
mode: 'dark', // 'light' | 'dark' | 'auto'
|
|
104
|
-
primaryColor: '#8b5cf6',
|
|
105
|
-
backgroundColor: '#1a1a1a',
|
|
106
|
-
borderRadius: '16px',
|
|
107
|
-
fontFamily: 'Inter, sans-serif',
|
|
108
|
-
overlayBackground: 'rgba(0, 0, 0, 0.8)',
|
|
109
|
-
modalBackground: '#1a1a1a',
|
|
110
|
-
textColor: '#ffffff',
|
|
111
|
-
buttonHoverColor: '#252525',
|
|
112
|
-
},
|
|
113
|
-
}}
|
|
114
|
-
>
|
|
115
|
-
<App />
|
|
116
|
-
</WalletProvider>
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Custom Connect Button
|
|
120
|
-
|
|
121
|
-
```tsx
|
|
122
|
-
<ConnectButton
|
|
123
|
-
label="Connect Wallet"
|
|
124
|
-
showBalance={true}
|
|
125
|
-
theme={customTheme}
|
|
126
|
-
onConnect={() => console.log('Connected!')}
|
|
127
|
-
onDisconnect={() => console.log('Disconnected!')}
|
|
128
|
-
/>
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
## π° Balance Checking
|
|
132
|
-
|
|
133
|
-
### Automatic Balance Updates
|
|
134
|
-
|
|
135
|
-
Balances are fetched automatically:
|
|
136
|
-
- β
When wallet connects
|
|
137
|
-
- β
Every 30 seconds while connected
|
|
138
|
-
- β
When network switches
|
|
139
|
-
- β
When manually triggered
|
|
140
|
-
|
|
141
|
-
### Using Balances
|
|
142
|
-
|
|
143
|
-
```tsx
|
|
144
|
-
import { useWallet, getNativeBalance, formatBalance } from 'stellar-wallet-kit';
|
|
145
|
-
|
|
146
|
-
function BalanceDisplay() {
|
|
147
|
-
const { account, isLoadingBalances, refreshBalances } = useWallet();
|
|
148
|
-
|
|
149
|
-
if (!account?.balances) return null;
|
|
150
|
-
|
|
151
|
-
const xlmBalance = getNativeBalance(account.balances);
|
|
98
|
+
---
|
|
152
99
|
|
|
153
|
-
|
|
154
|
-
<div>
|
|
155
|
-
<h3>{formatBalance(xlmBalance, 2)} XLM</h3>
|
|
156
|
-
<button onClick={refreshBalances} disabled={isLoadingBalances}>
|
|
157
|
-
{isLoadingBalances ? 'Loading...' : 'Refresh'}
|
|
158
|
-
</button>
|
|
159
|
-
</div>
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
```
|
|
100
|
+
## π Supported Wallets
|
|
163
101
|
|
|
164
|
-
|
|
102
|
+
| Wallet | Type | Auto-Reconnect |
|
|
103
|
+
| ------------- | ----------------- | -------------- |
|
|
104
|
+
| **Freighter** | Browser extension | β
|
|
|
105
|
+
| **Albedo** | Web-based (popup) | β |
|
|
165
106
|
|
|
166
|
-
|
|
167
|
-
import {
|
|
168
|
-
getNativeBalance, // Get XLM balance
|
|
169
|
-
formatBalance, // Format for display
|
|
170
|
-
getAssetBalance, // Get specific asset balance
|
|
171
|
-
hasSufficientBalance, // Check if enough funds
|
|
172
|
-
groupBalancesByType, // Group balances by type
|
|
173
|
-
} from 'stellar-wallet-kit';
|
|
107
|
+
---
|
|
174
108
|
|
|
175
|
-
|
|
176
|
-
const xlm = getNativeBalance(account.balances);
|
|
109
|
+
## π Albedo Wallet Integration (Important)
|
|
177
110
|
|
|
178
|
-
|
|
179
|
-
const usdc = getAssetBalance(account.balances, 'USDC', issuerAddress);
|
|
111
|
+
Albedo is a **web-based wallet**, not a browser extension.
|
|
180
112
|
|
|
181
|
-
|
|
182
|
-
const formatted = formatBalance("1234.5678900", 2); // "1234.56"
|
|
113
|
+
Because of this, it **cannot inject APIs** into your app and **requires a callback route** to return results.
|
|
183
114
|
|
|
184
|
-
|
|
185
|
-
const canPay = hasSufficientBalance(account.balances, '100', 'USDC');
|
|
186
|
-
```
|
|
115
|
+
This is **intentional and secure by design**.
|
|
187
116
|
|
|
188
|
-
|
|
117
|
+
---
|
|
189
118
|
|
|
190
|
-
###
|
|
119
|
+
### π§ How Albedo Works
|
|
191
120
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
isConnecting, // Loading state
|
|
198
|
-
isLoadingBalances, // Balance loading state
|
|
199
|
-
error, // Error if any
|
|
200
|
-
network, // Current network
|
|
201
|
-
selectedWallet, // Selected wallet type
|
|
202
|
-
availableWallets, // List of available wallets
|
|
203
|
-
|
|
204
|
-
// Methods
|
|
205
|
-
connect, // Connect to a wallet
|
|
206
|
-
disconnect, // Disconnect wallet
|
|
207
|
-
signTransaction, // Sign a transaction
|
|
208
|
-
signAuthEntry, // Sign authorization entry
|
|
209
|
-
switchNetwork, // Switch networks
|
|
210
|
-
refreshBalances, // Manually refresh balances
|
|
211
|
-
} = useWallet();
|
|
212
|
-
```
|
|
121
|
+
1. Your app opens Albedo in a popup
|
|
122
|
+
2. User approves the action in Albedo
|
|
123
|
+
3. Albedo redirects the popup to a callback URL
|
|
124
|
+
4. The callback sends data back to your app
|
|
125
|
+
5. The popup closes and the wallet is connected
|
|
213
126
|
|
|
214
|
-
|
|
127
|
+
If the callback route is missing, **Albedo will open but never connect**.
|
|
215
128
|
|
|
216
|
-
|
|
217
|
-
// Connect to default/auto-detected wallet
|
|
218
|
-
await connect();
|
|
129
|
+
---
|
|
219
130
|
|
|
220
|
-
|
|
221
|
-
await connect(WalletType.FREIGHTER);
|
|
222
|
-
```
|
|
131
|
+
## β οΈ Required: Add an Albedo Callback Route (App-side)
|
|
223
132
|
|
|
224
|
-
|
|
133
|
+
Because this SDK is **framework-agnostic**, it **cannot create routes for you**.
|
|
225
134
|
|
|
226
|
-
|
|
227
|
-
const response = await signTransaction(xdr, {
|
|
228
|
-
network: 'TESTNET',
|
|
229
|
-
networkPassphrase: 'Test SDF Network ; September 2015',
|
|
230
|
-
accountToSign: 'GXXXXXX...',
|
|
231
|
-
});
|
|
135
|
+
Your app **must define** a callback route.
|
|
232
136
|
|
|
233
|
-
|
|
234
|
-
```
|
|
137
|
+
---
|
|
235
138
|
|
|
236
|
-
###
|
|
139
|
+
### Example: Next.js (Pages Router)
|
|
237
140
|
|
|
238
141
|
```tsx
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
142
|
+
// pages/albedo-callback.tsx
|
|
143
|
+
import { useEffect } from 'react';
|
|
144
|
+
|
|
145
|
+
export default function AlbedoCallback() {
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
const params = Object.fromEntries(
|
|
148
|
+
new URLSearchParams(window.location.search)
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (window.opener) {
|
|
152
|
+
window.opener.postMessage(
|
|
153
|
+
{ type: 'ALBEDO_RESULT', payload: params },
|
|
154
|
+
window.location.origin
|
|
155
|
+
);
|
|
156
|
+
}
|
|
245
157
|
|
|
246
|
-
|
|
158
|
+
window.close();
|
|
159
|
+
}, []);
|
|
247
160
|
|
|
248
|
-
|
|
249
|
-
interface StellarWalletKitConfig {
|
|
250
|
-
network?: NetworkType; // 'PUBLIC' | 'TESTNET' | 'FUTURENET' | 'STANDALONE'
|
|
251
|
-
defaultWallet?: WalletType; // Default wallet to connect
|
|
252
|
-
autoConnect?: boolean; // Auto-reconnect on page load
|
|
253
|
-
theme?: WalletTheme; // Custom theme
|
|
254
|
-
appName?: string; // Your app name
|
|
255
|
-
appIcon?: string; // Your app icon URL
|
|
161
|
+
return <p>Connecting walletβ¦</p>;
|
|
256
162
|
}
|
|
257
163
|
```
|
|
258
164
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
The kit works seamlessly with Next.js 13+ App Router:
|
|
165
|
+
---
|
|
262
166
|
|
|
263
|
-
###
|
|
167
|
+
### Example: Next.js (App Router)
|
|
264
168
|
|
|
265
169
|
```tsx
|
|
266
|
-
// app/
|
|
170
|
+
// app/albedo-callback/page.tsx
|
|
267
171
|
'use client';
|
|
268
172
|
|
|
269
|
-
import {
|
|
173
|
+
import { useEffect } from 'react';
|
|
270
174
|
|
|
271
|
-
export function
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
```
|
|
175
|
+
export default function AlbedoCallback() {
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
const params = Object.fromEntries(
|
|
178
|
+
new URLSearchParams(window.location.search)
|
|
179
|
+
);
|
|
279
180
|
|
|
280
|
-
|
|
181
|
+
if (window.opener) {
|
|
182
|
+
window.opener.postMessage(
|
|
183
|
+
{ type: 'ALBEDO_RESULT', payload: params },
|
|
184
|
+
window.location.origin
|
|
185
|
+
);
|
|
186
|
+
}
|
|
281
187
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
import { Providers } from './providers';
|
|
188
|
+
window.close();
|
|
189
|
+
}, []);
|
|
285
190
|
|
|
286
|
-
|
|
287
|
-
return (
|
|
288
|
-
<html lang="en">
|
|
289
|
-
<body>
|
|
290
|
-
<Providers>{children}</Providers>
|
|
291
|
-
</body>
|
|
292
|
-
</html>
|
|
293
|
-
);
|
|
191
|
+
return <p>Connecting walletβ¦</p>;
|
|
294
192
|
}
|
|
295
193
|
```
|
|
296
194
|
|
|
297
|
-
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### Example: React Router
|
|
298
198
|
|
|
299
199
|
```tsx
|
|
300
|
-
|
|
301
|
-
|
|
200
|
+
function AlbedoCallback() {
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
const params = Object.fromEntries(
|
|
203
|
+
new URLSearchParams(window.location.search)
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
if (window.opener) {
|
|
207
|
+
window.opener.postMessage(
|
|
208
|
+
{ type: 'ALBEDO_RESULT', payload: params },
|
|
209
|
+
window.location.origin
|
|
210
|
+
);
|
|
211
|
+
}
|
|
302
212
|
|
|
303
|
-
|
|
213
|
+
window.close();
|
|
214
|
+
}, []);
|
|
304
215
|
|
|
305
|
-
|
|
306
|
-
const { isConnected } = useWallet();
|
|
307
|
-
return <ConnectButton />;
|
|
216
|
+
return <p>Connecting walletβ¦</p>;
|
|
308
217
|
}
|
|
309
218
|
```
|
|
310
219
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
Supports all Stellar networks:
|
|
314
|
-
|
|
315
|
-
```tsx
|
|
316
|
-
import { NetworkType } from 'stellar-wallet-kit';
|
|
317
|
-
|
|
318
|
-
NetworkType.PUBLIC // Mainnet
|
|
319
|
-
NetworkType.TESTNET // Testnet
|
|
320
|
-
NetworkType.FUTURENET // Futurenet
|
|
321
|
-
NetworkType.STANDALONE // Local network
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
## π Supported Wallets
|
|
325
|
-
|
|
326
|
-
Currently supported:
|
|
327
|
-
- β
**Freighter** - Browser extension wallet
|
|
328
|
-
|
|
329
|
-
Coming soon:
|
|
330
|
-
- π xBull
|
|
331
|
-
- π Albedo
|
|
332
|
-
- π Rabet
|
|
333
|
-
- π WalletConnect
|
|
334
|
-
|
|
335
|
-
## π οΈ Advanced Usage
|
|
220
|
+
---
|
|
336
221
|
|
|
337
|
-
|
|
222
|
+
## π Connecting Explicitly to Albedo
|
|
338
223
|
|
|
339
224
|
```tsx
|
|
340
|
-
import {
|
|
341
|
-
import { useWallet, WalletModal } from 'stellar-wallet-kit';
|
|
225
|
+
import { WalletType, useWallet } from 'stellar-wallet-kit';
|
|
342
226
|
|
|
343
|
-
|
|
344
|
-
const [showModal, setShowModal] = useState(false);
|
|
345
|
-
const { availableWallets, connect } = useWallet();
|
|
227
|
+
const { connect } = useWallet();
|
|
346
228
|
|
|
347
|
-
|
|
348
|
-
<>
|
|
349
|
-
<button onClick={() => setShowModal(true)}>
|
|
350
|
-
Connect Wallet
|
|
351
|
-
</button>
|
|
352
|
-
|
|
353
|
-
<WalletModal
|
|
354
|
-
isOpen={showModal}
|
|
355
|
-
onClose={() => setShowModal(false)}
|
|
356
|
-
wallets={availableWallets}
|
|
357
|
-
onSelectWallet={connect}
|
|
358
|
-
/>
|
|
359
|
-
</>
|
|
360
|
-
);
|
|
361
|
-
}
|
|
229
|
+
await connect(WalletType.ALBEDO);
|
|
362
230
|
```
|
|
363
231
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
```tsx
|
|
367
|
-
import { useWallet, hasSufficientBalance } from 'stellar-wallet-kit';
|
|
368
|
-
|
|
369
|
-
function PaymentForm() {
|
|
370
|
-
const { account, signTransaction } = useWallet();
|
|
371
|
-
const [amount, setAmount] = useState('');
|
|
372
|
-
|
|
373
|
-
const handlePay = async () => {
|
|
374
|
-
// Check balance before signing
|
|
375
|
-
if (!hasSufficientBalance(account.balances, amount)) {
|
|
376
|
-
alert('Insufficient balance!');
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// Build and sign transaction
|
|
381
|
-
const signed = await signTransaction(transactionXDR);
|
|
382
|
-
// Submit to network...
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
return (
|
|
386
|
-
<form onSubmit={handlePay}>
|
|
387
|
-
<input value={amount} onChange={e => setAmount(e.target.value)} />
|
|
388
|
-
<button type="submit">Pay</button>
|
|
389
|
-
</form>
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
```
|
|
232
|
+
---
|
|
393
233
|
|
|
394
|
-
|
|
234
|
+
## π° Balance Utilities
|
|
395
235
|
|
|
396
236
|
```tsx
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
await connect();
|
|
404
|
-
} catch (err) {
|
|
405
|
-
console.error('Failed to connect:', err);
|
|
406
|
-
}
|
|
407
|
-
};
|
|
237
|
+
import {
|
|
238
|
+
getNativeBalance,
|
|
239
|
+
getAssetBalance,
|
|
240
|
+
formatBalance,
|
|
241
|
+
hasSufficientBalance,
|
|
242
|
+
} from 'stellar-wallet-kit';
|
|
408
243
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
{error && <p className="error">{error.message}</p>}
|
|
412
|
-
{txError && <p className="error">{txError}</p>}
|
|
413
|
-
<button onClick={handleConnect}>Connect</button>
|
|
414
|
-
</div>
|
|
415
|
-
);
|
|
416
|
-
}
|
|
244
|
+
const xlm = getNativeBalance(account.balances);
|
|
245
|
+
const usdc = getAssetBalance(account.balances, 'USDC', issuer);
|
|
417
246
|
```
|
|
418
247
|
|
|
419
|
-
|
|
248
|
+
---
|
|
420
249
|
|
|
421
|
-
|
|
250
|
+
## π¨ Theme Customization
|
|
422
251
|
|
|
423
252
|
```tsx
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
253
|
+
<WalletProvider
|
|
254
|
+
config={{
|
|
255
|
+
theme: {
|
|
256
|
+
mode: 'dark',
|
|
257
|
+
primaryColor: '#8b5cf6',
|
|
258
|
+
borderRadius: '16px',
|
|
259
|
+
},
|
|
260
|
+
}}
|
|
261
|
+
>
|
|
262
|
+
<App />
|
|
263
|
+
</WalletProvider>
|
|
432
264
|
```
|
|
433
265
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
The package provides unstyled components that you can customize:
|
|
437
|
-
|
|
438
|
-
### Using Tailwind CSS
|
|
439
|
-
|
|
440
|
-
```tsx
|
|
441
|
-
<ConnectButton
|
|
442
|
-
className="px-6 py-3 bg-purple-600 text-white rounded-lg hover:bg-purple-700"
|
|
443
|
-
/>
|
|
444
|
-
```
|
|
266
|
+
---
|
|
445
267
|
|
|
446
|
-
|
|
268
|
+
## π― `useWallet()` API
|
|
447
269
|
|
|
448
270
|
```tsx
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
271
|
+
const {
|
|
272
|
+
account,
|
|
273
|
+
isConnected,
|
|
274
|
+
isConnecting,
|
|
275
|
+
error,
|
|
276
|
+
network,
|
|
277
|
+
selectedWallet,
|
|
278
|
+
availableWallets,
|
|
279
|
+
|
|
280
|
+
connect,
|
|
281
|
+
disconnect,
|
|
282
|
+
signTransaction,
|
|
283
|
+
signAuthEntry,
|
|
284
|
+
switchNetwork,
|
|
285
|
+
refreshBalances,
|
|
286
|
+
|
|
287
|
+
supports,
|
|
288
|
+
} = useWallet();
|
|
457
289
|
```
|
|
458
290
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
Generate safe test transactions:
|
|
462
|
-
|
|
463
|
-
```bash
|
|
464
|
-
npm install @stellar/stellar-sdk
|
|
465
|
-
```
|
|
291
|
+
---
|
|
466
292
|
|
|
467
|
-
|
|
468
|
-
import * as StellarSdk from '@stellar/stellar-sdk';
|
|
293
|
+
## π§ Wallet Capabilities (`supports`)
|
|
469
294
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const account = await server.loadAccount(publicKey);
|
|
476
|
-
|
|
477
|
-
const transaction = new StellarSdk.TransactionBuilder(account, {
|
|
478
|
-
fee: StellarSdk.BASE_FEE,
|
|
479
|
-
networkPassphrase: StellarSdk.Networks.TESTNET,
|
|
480
|
-
})
|
|
481
|
-
.addMemo(StellarSdk.Memo.text('Test transaction'))
|
|
482
|
-
.setTimeout(300)
|
|
483
|
-
.build();
|
|
484
|
-
|
|
485
|
-
return transaction.toXDR();
|
|
295
|
+
```ts
|
|
296
|
+
supports = {
|
|
297
|
+
silentReconnect: boolean;
|
|
298
|
+
networkDetection: boolean;
|
|
299
|
+
authEntrySigning: boolean;
|
|
486
300
|
}
|
|
487
301
|
```
|
|
488
302
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
492
|
-
|
|
493
|
-
### Development Setup
|
|
303
|
+
Useful for conditional UI and safer flows.
|
|
494
304
|
|
|
495
|
-
|
|
496
|
-
# Clone the repository
|
|
497
|
-
git clone https://github.com/tusharpamnani/stellar-wallet-kit
|
|
498
|
-
cd stellar-wallet-kit
|
|
305
|
+
---
|
|
499
306
|
|
|
500
|
-
|
|
501
|
-
npm install
|
|
307
|
+
## π± Next.js App Router Setup
|
|
502
308
|
|
|
503
|
-
|
|
504
|
-
|
|
309
|
+
```tsx
|
|
310
|
+
'use client';
|
|
505
311
|
|
|
506
|
-
|
|
507
|
-
npm run dev
|
|
312
|
+
import { WalletProvider } from 'stellar-wallet-kit';
|
|
508
313
|
|
|
509
|
-
|
|
510
|
-
|
|
314
|
+
export function Providers({ children }) {
|
|
315
|
+
return <WalletProvider>{children}</WalletProvider>;
|
|
316
|
+
}
|
|
511
317
|
```
|
|
512
318
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
1. Create a new adapter in `src/adapters/`
|
|
516
|
-
2. Implement the `WalletAdapter` interface
|
|
517
|
-
3. Register it in `WalletContext.tsx`
|
|
518
|
-
4. Add metadata and icon
|
|
519
|
-
5. Submit a PR!
|
|
520
|
-
|
|
521
|
-
## π Examples
|
|
522
|
-
|
|
523
|
-
Check out the `/example` directory for complete working examples:
|
|
524
|
-
|
|
525
|
-
- Basic wallet connection
|
|
526
|
-
- Balance display
|
|
527
|
-
- Transaction signing
|
|
528
|
-
- Payment forms
|
|
529
|
-
- Next.js integration
|
|
319
|
+
---
|
|
530
320
|
|
|
531
321
|
## π Troubleshooting
|
|
532
322
|
|
|
533
|
-
###
|
|
534
|
-
**Solution:** Add `'use client'` directive to the top of your file.
|
|
323
|
+
### Albedo popup opens but doesnβt connect
|
|
535
324
|
|
|
536
|
-
|
|
537
|
-
|
|
325
|
+
β Missing callback route
|
|
326
|
+
β Callback URL mismatch
|
|
327
|
+
β Popup blocked by browser
|
|
538
328
|
|
|
539
329
|
### Freighter not detected
|
|
540
|
-
**Solution:** Make sure Freighter extension is installed and enabled in your browser.
|
|
541
330
|
|
|
542
|
-
|
|
543
|
-
**Solution:** Ensure your account is funded on the selected network. Use the [Stellar Laboratory](https://laboratory.stellar.org/#account-creator) to fund testnet accounts.
|
|
331
|
+
β Ensure extension is installed & enabled
|
|
544
332
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
- [Freighter API Docs](https://docs.freighter.app/)
|
|
548
|
-
- [Stellar Docs](https://developers.stellar.org/)
|
|
549
|
-
- [Stellar SDK](https://stellar.github.io/js-stellar-sdk/)
|
|
333
|
+
---
|
|
550
334
|
|
|
551
335
|
## πΊοΈ Roadmap
|
|
552
336
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
- [ ] Transaction history
|
|
562
|
-
- [ ] Multi-account support
|
|
563
|
-
- [ ] Mobile wallet support
|
|
564
|
-
- [ ] Hardware wallet support
|
|
565
|
-
|
|
566
|
-
## π License
|
|
567
|
-
|
|
568
|
-
MIT Β© TusharPamnani
|
|
337
|
+
* [x] Freighter support
|
|
338
|
+
* [x] Albedo support
|
|
339
|
+
* [x] Balance utilities
|
|
340
|
+
* [ ] xBull
|
|
341
|
+
* [ ] Rabet
|
|
342
|
+
* [ ] WalletConnect
|
|
343
|
+
* [ ] Mobile deep-link wallets
|
|
344
|
+
* [ ] Hardware wallets
|
|
569
345
|
|
|
570
|
-
|
|
346
|
+
---
|
|
571
347
|
|
|
572
|
-
|
|
573
|
-
- Built for the [Stellar](https://stellar.org/) ecosystem
|
|
574
|
-
- Thanks to the Stellar Developer Foundation
|
|
348
|
+
## π License
|
|
575
349
|
|
|
576
|
-
|
|
350
|
+
MIT Β© Tushar Pamnani
|
|
577
351
|
|
|
578
|
-
|
|
579
|
-
- [Stellar Discord](https://discord.gg/stellardev)
|
|
580
|
-
- [Stack Exchange](https://stellar.stackexchange.com/)
|
|
352
|
+
---
|
|
581
353
|
|
|
582
354
|
## π Show Your Support
|
|
583
355
|
|
|
584
|
-
If this project
|
|
585
|
-
|
|
586
|
-
---
|
|
356
|
+
If this project helps you, please βοΈ it on GitHub.
|
|
587
357
|
|
|
588
|
-
|
|
358
|
+
Built with β€οΈ for the Stellar ecosystem.
|