@arcadiasol/game-sdk 1.0.0 → 1.1.0
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 +63 -382
- package/dist/esm/api-client.d.ts +54 -0
- package/dist/esm/api-client.d.ts.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +410 -98
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/payment.d.ts +12 -3
- package/dist/esm/payment.d.ts.map +1 -1
- package/dist/esm/sdk.d.ts +2 -1
- package/dist/esm/sdk.d.ts.map +1 -1
- package/dist/esm/types.d.ts +16 -6
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/wallet.d.ts +4 -2
- package/dist/esm/wallet.d.ts.map +1 -1
- package/dist/umd/arcadia-game-sdk.js +410 -97
- package/dist/umd/arcadia-game-sdk.js.map +1 -1
- package/dist/umd/arcadia-game-sdk.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,458 +1,139 @@
|
|
|
1
1
|
# Arcadia Game SDK
|
|
2
2
|
|
|
3
|
-
SDK for integrating Arcadia wallet and payment features into Web3 games.
|
|
3
|
+
SDK for integrating Arcadia wallet and payment features into Web3 games.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **Wallet
|
|
8
|
-
- **Payment Processing** - Pay-to-play and in-game purchases
|
|
9
|
-
- **
|
|
10
|
-
- **Iframe Support** - Works
|
|
11
|
-
- **
|
|
12
|
-
- **TypeScript Support** - Full type definitions included
|
|
7
|
+
- ✅ **Wallet Integration** - Get wallet address, check connection status
|
|
8
|
+
- ✅ **Payment Processing** - Pay-to-play and in-game purchases
|
|
9
|
+
- ✅ **Iframe Support** - Works seamlessly in Arcadia iframes
|
|
10
|
+
- ✅ **Non-Iframe Support** - Works with direct API calls for native apps
|
|
11
|
+
- ✅ **Stats Tracking** - Track playtime and online status (non-iframe mode)
|
|
13
12
|
|
|
14
13
|
## Installation
|
|
15
14
|
|
|
16
15
|
### NPM
|
|
17
16
|
|
|
18
17
|
```bash
|
|
19
|
-
npm install @
|
|
18
|
+
npm install @arcadiasol/game-sdk
|
|
20
19
|
```
|
|
21
20
|
|
|
22
21
|
### CDN
|
|
23
22
|
|
|
24
23
|
```html
|
|
25
|
-
|
|
26
|
-
<script src="https://cdn.arcadia.com/sdk/v1/arcadia-game-sdk.js"></script>
|
|
27
|
-
|
|
28
|
-
<!-- Production (Minified) -->
|
|
29
|
-
<script src="https://cdn.arcadia.com/sdk/v1/arcadia-game-sdk.min.js"></script>
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/@arcadiasol/game-sdk@latest/dist/umd/arcadia-game-sdk.js"></script>
|
|
30
25
|
```
|
|
31
26
|
|
|
32
27
|
## Quick Start
|
|
33
28
|
|
|
34
|
-
###
|
|
29
|
+
### Iframe Mode (Web Games)
|
|
35
30
|
|
|
36
31
|
```typescript
|
|
37
|
-
import
|
|
32
|
+
import ArcadiaSDK from '@arcadiasol/game-sdk';
|
|
38
33
|
|
|
39
|
-
// Initialize SDK
|
|
40
34
|
const arcadia = new ArcadiaSDK({
|
|
41
35
|
gameId: 'your-game-id',
|
|
42
36
|
});
|
|
43
37
|
|
|
44
38
|
await arcadia.init();
|
|
45
39
|
|
|
46
|
-
// Get wallet address
|
|
40
|
+
// Get wallet address
|
|
47
41
|
const walletAddress = await arcadia.getWalletAddress();
|
|
48
42
|
|
|
49
|
-
if (!walletAddress) {
|
|
50
|
-
console.log('Please connect your wallet in Arcadia');
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Link save data to wallet address
|
|
55
|
-
const saveData = await loadSaveDataByWallet(walletAddress);
|
|
56
|
-
|
|
57
43
|
// Pay to play
|
|
58
|
-
const result = await arcadia.payment.payToPlay(0.
|
|
59
|
-
console.log('Payment successful:', result.txSignature);
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### CDN Usage
|
|
63
|
-
|
|
64
|
-
```html
|
|
65
|
-
<!DOCTYPE html>
|
|
66
|
-
<html>
|
|
67
|
-
<head>
|
|
68
|
-
<script src="https://cdn.arcadia.com/sdk/v1/arcadia-game-sdk.min.js"></script>
|
|
69
|
-
</head>
|
|
70
|
-
<body>
|
|
71
|
-
<script>
|
|
72
|
-
// Initialize SDK
|
|
73
|
-
const arcadia = new ArcadiaGameSDK({
|
|
74
|
-
gameId: 'your-game-id',
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
arcadia.init().then(async () => {
|
|
78
|
-
// Get wallet address
|
|
79
|
-
const walletAddress = await arcadia.getWalletAddress();
|
|
80
|
-
|
|
81
|
-
if (!walletAddress) {
|
|
82
|
-
alert('Please connect your wallet in Arcadia');
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Use wallet address as user ID
|
|
87
|
-
console.log('User wallet:', walletAddress);
|
|
88
|
-
});
|
|
89
|
-
</script>
|
|
90
|
-
</body>
|
|
91
|
-
</html>
|
|
44
|
+
const result = await arcadia.payment.payToPlay(0.1, 'SOL');
|
|
92
45
|
```
|
|
93
46
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
### Initialization
|
|
97
|
-
|
|
98
|
-
#### `new ArcadiaSDK(config: SDKConfig)`
|
|
99
|
-
|
|
100
|
-
Create a new SDK instance.
|
|
47
|
+
### Non-Iframe Mode (Native Apps / External Games)
|
|
101
48
|
|
|
102
|
-
**Parameters:**
|
|
103
|
-
- `config.gameId` (string, required) - Your unique game identifier
|
|
104
|
-
- `config.parentOrigin` (string, optional) - Parent window origin for security (default: '*')
|
|
105
|
-
- `config.timeout` (number, optional) - Request timeout in milliseconds (default: 30000)
|
|
106
|
-
|
|
107
|
-
**Example:**
|
|
108
49
|
```typescript
|
|
50
|
+
import ArcadiaSDK from '@arcadiasol/game-sdk';
|
|
51
|
+
|
|
109
52
|
const arcadia = new ArcadiaSDK({
|
|
110
|
-
gameId: '
|
|
111
|
-
|
|
112
|
-
|
|
53
|
+
gameId: 'your-game-id',
|
|
54
|
+
apiBaseURL: 'https://arcadia.com', // Required for non-iframe
|
|
55
|
+
authToken: 'your-auth-token', // Optional: if you have auth token
|
|
56
|
+
walletAddress: 'your-wallet-address', // Optional: if you know wallet address
|
|
113
57
|
});
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
#### `init(): Promise<void>`
|
|
117
58
|
|
|
118
|
-
Initialize SDK and request initialization data from parent window. Call this after creating the SDK instance.
|
|
119
|
-
|
|
120
|
-
**Example:**
|
|
121
|
-
```typescript
|
|
122
59
|
await arcadia.init();
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### Wallet Address
|
|
126
|
-
|
|
127
|
-
#### `getWalletAddress(): Promise<string | null>`
|
|
128
60
|
|
|
129
|
-
Get
|
|
130
|
-
|
|
131
|
-
**Returns:** Wallet address (string) or null if not connected
|
|
132
|
-
|
|
133
|
-
**Example:**
|
|
134
|
-
```typescript
|
|
61
|
+
// Get wallet address
|
|
135
62
|
const walletAddress = await arcadia.getWalletAddress();
|
|
136
63
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
showMessage('Please connect your wallet');
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Use wallet address as user ID
|
|
144
|
-
const userId = walletAddress;
|
|
145
|
-
const saveData = await loadSaveDataByWallet(walletAddress);
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
#### `isWalletConnected(): Promise<boolean>`
|
|
149
|
-
|
|
150
|
-
Check if wallet is currently connected.
|
|
151
|
-
|
|
152
|
-
**Returns:** true if connected, false otherwise
|
|
153
|
-
|
|
154
|
-
**Example:**
|
|
155
|
-
```typescript
|
|
156
|
-
const connected = await arcadia.isWalletConnected();
|
|
157
|
-
if (!connected) {
|
|
158
|
-
showMessage('Please connect your wallet');
|
|
159
|
-
}
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
#### `onWalletChange(callback: (connected: boolean, address: string | null) => void): void`
|
|
163
|
-
|
|
164
|
-
Listen for wallet connection changes.
|
|
165
|
-
|
|
166
|
-
**Example:**
|
|
167
|
-
```typescript
|
|
168
|
-
arcadia.onWalletChange((connected, address) => {
|
|
169
|
-
if (!connected) {
|
|
170
|
-
// Wallet disconnected - pause game
|
|
171
|
-
pauseGame();
|
|
172
|
-
showMessage('Wallet disconnected. Please reconnect.');
|
|
173
|
-
} else {
|
|
174
|
-
// Wallet reconnected - resume game
|
|
175
|
-
resumeGame();
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
#### `offWalletChange(callback: Function): void`
|
|
181
|
-
|
|
182
|
-
Remove a wallet change listener.
|
|
183
|
-
|
|
184
|
-
**Example:**
|
|
185
|
-
```typescript
|
|
186
|
-
const callback = (connected, address) => { /* ... */ };
|
|
187
|
-
arcadia.onWalletChange(callback);
|
|
188
|
-
// Later...
|
|
189
|
-
arcadia.offWalletChange(callback);
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Payments
|
|
193
|
-
|
|
194
|
-
#### `payment.payToPlay(amount: number, token: 'SOL' | 'USDC'): Promise<PaymentResult>`
|
|
195
|
-
|
|
196
|
-
Process a pay-to-play payment (one-time payment to access game).
|
|
197
|
-
|
|
198
|
-
**Parameters:**
|
|
199
|
-
- `amount` (number) - Payment amount (must be > 0)
|
|
200
|
-
- `token` ('SOL' | 'USDC') - Token type
|
|
201
|
-
|
|
202
|
-
**Returns:** `PaymentResult` object with complete payment details:
|
|
203
|
-
- `success` (boolean) - Whether payment was successful
|
|
204
|
-
- `txSignature` (string) - Blockchain transaction signature (proof of payment)
|
|
205
|
-
- `amount` (number) - Amount paid by user
|
|
206
|
-
- `token` ('SOL' | 'USDC') - Token type used
|
|
207
|
-
- `timestamp` (string) - ISO timestamp when payment completed
|
|
208
|
-
- `purchaseId` (string, optional) - Arcadia purchase ID for tracking
|
|
209
|
-
- `platformFee` (number, optional) - Platform fee deducted
|
|
210
|
-
- `developerAmount` (number, optional) - Amount received by developer (after fees)
|
|
211
|
-
|
|
212
|
-
**Example:**
|
|
213
|
-
```typescript
|
|
214
|
-
try {
|
|
215
|
-
const result = await arcadia.payment.payToPlay(0.5, 'SOL');
|
|
216
|
-
|
|
217
|
-
// All payment details are included - no need to query blockchain
|
|
218
|
-
console.log('Payment successful!');
|
|
219
|
-
console.log('Transaction:', result.txSignature);
|
|
220
|
-
console.log('Amount paid:', result.amount, result.token);
|
|
221
|
-
console.log('Completed at:', result.timestamp);
|
|
222
|
-
console.log('Purchase ID:', result.purchaseId);
|
|
223
|
-
console.log('Platform fee:', result.platformFee);
|
|
224
|
-
console.log('Developer receives:', result.developerAmount);
|
|
225
|
-
|
|
226
|
-
// Store in your database for reference
|
|
227
|
-
await savePurchase({
|
|
228
|
-
txSignature: result.txSignature,
|
|
229
|
-
amount: result.amount,
|
|
230
|
-
token: result.token,
|
|
231
|
-
timestamp: result.timestamp,
|
|
232
|
-
purchaseId: result.purchaseId,
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// Start game
|
|
236
|
-
startGame();
|
|
237
|
-
} catch (error) {
|
|
238
|
-
console.error('Payment failed:', error.message);
|
|
239
|
-
showError('Payment failed. Please try again.');
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
#### `payment.purchaseItem(itemId: string, amount: number, token: 'SOL' | 'USDC'): Promise<PaymentResult>`
|
|
244
|
-
|
|
245
|
-
Purchase an in-game item.
|
|
64
|
+
// Track playtime
|
|
65
|
+
await arcadia.stats.updatePlaytime(1.5, 'playing');
|
|
246
66
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
- `amount` (number) - Payment amount (must be > 0)
|
|
250
|
-
- `token` ('SOL' | 'USDC') - Token type
|
|
67
|
+
// Update online status
|
|
68
|
+
await arcadia.stats.updateOnlineStatus(true);
|
|
251
69
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
try {
|
|
257
|
-
const result = await arcadia.payment.purchaseItem('sword-001', 1.0, 'SOL');
|
|
258
|
-
|
|
259
|
-
// All payment details included - verify and process
|
|
260
|
-
if (result.success && result.amount === 1.0 && result.token === 'SOL') {
|
|
261
|
-
// Payment verified - add item to inventory
|
|
262
|
-
addItemToInventory('sword-001');
|
|
263
|
-
|
|
264
|
-
// Log purchase for analytics
|
|
265
|
-
logPurchase({
|
|
266
|
-
itemId: 'sword-001',
|
|
267
|
-
txSignature: result.txSignature,
|
|
268
|
-
amount: result.amount,
|
|
269
|
-
timestamp: result.timestamp,
|
|
270
|
-
purchaseId: result.purchaseId,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
} catch (error) {
|
|
274
|
-
console.error('Purchase failed:', error.message);
|
|
275
|
-
showError('Purchase failed. Please try again.');
|
|
276
|
-
}
|
|
70
|
+
// Pay to play (requires transaction signature)
|
|
71
|
+
// Note: You must sign the transaction yourself in non-iframe mode
|
|
72
|
+
const txSignature = await signTransaction(...); // Your signing logic
|
|
73
|
+
const result = await arcadia.payment.payToPlay(0.1, 'SOL', txSignature);
|
|
277
74
|
```
|
|
278
75
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
#### `isInIframe(): boolean`
|
|
282
|
-
|
|
283
|
-
Check if SDK is running in an iframe environment.
|
|
284
|
-
|
|
285
|
-
**Returns:** true if in iframe, false otherwise
|
|
286
|
-
|
|
287
|
-
#### `isInitialized(): boolean`
|
|
288
|
-
|
|
289
|
-
Check if SDK has been initialized.
|
|
290
|
-
|
|
291
|
-
**Returns:** true if initialized, false otherwise
|
|
292
|
-
|
|
293
|
-
#### `getConfig(): SDKConfig`
|
|
294
|
-
|
|
295
|
-
Get current SDK configuration.
|
|
296
|
-
|
|
297
|
-
**Returns:** SDK configuration object
|
|
298
|
-
|
|
299
|
-
#### `destroy(): void`
|
|
300
|
-
|
|
301
|
-
Cleanup SDK resources. Call this when game is unloaded.
|
|
302
|
-
|
|
303
|
-
## Error Handling
|
|
76
|
+
## API Reference
|
|
304
77
|
|
|
305
|
-
|
|
78
|
+
### Constructor
|
|
306
79
|
|
|
307
80
|
```typescript
|
|
308
|
-
|
|
309
|
-
ArcadiaSDKError,
|
|
310
|
-
WalletNotConnectedError,
|
|
311
|
-
PaymentFailedError,
|
|
312
|
-
TimeoutError,
|
|
313
|
-
InvalidConfigError,
|
|
314
|
-
NotInIframeError,
|
|
315
|
-
InvalidAmountError,
|
|
316
|
-
InvalidTokenError,
|
|
317
|
-
} from '@arcadia/game-sdk';
|
|
318
|
-
|
|
319
|
-
try {
|
|
320
|
-
await arcadia.payment.payToPlay(0.5, 'SOL');
|
|
321
|
-
} catch (error) {
|
|
322
|
-
if (error instanceof WalletNotConnectedError) {
|
|
323
|
-
showMessage('Please connect your wallet');
|
|
324
|
-
} else if (error instanceof PaymentFailedError) {
|
|
325
|
-
showError('Payment failed: ' + error.message);
|
|
326
|
-
} else if (error instanceof TimeoutError) {
|
|
327
|
-
showError('Request timed out. Please try again.');
|
|
328
|
-
} else {
|
|
329
|
-
showError('An error occurred: ' + error.message);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
81
|
+
new ArcadiaSDK(config: SDKConfig)
|
|
332
82
|
```
|
|
333
83
|
|
|
334
|
-
|
|
84
|
+
**Config Options:**
|
|
85
|
+
- `gameId` (string, required) - Your game identifier
|
|
86
|
+
- `parentOrigin` (string, optional) - Parent window origin for iframe security
|
|
87
|
+
- `timeout` (number, optional) - Request timeout in milliseconds (default: 30000)
|
|
88
|
+
- `apiBaseURL` (string, optional) - Base URL for API calls (required for non-iframe)
|
|
89
|
+
- `authToken` (string, optional) - Pre-authenticated token (non-iframe mode)
|
|
90
|
+
- `walletAddress` (string, optional) - Wallet address (non-iframe mode)
|
|
335
91
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
```typescript
|
|
339
|
-
// Get wallet address
|
|
340
|
-
const walletAddress = await arcadia.getWalletAddress();
|
|
92
|
+
### Methods
|
|
341
93
|
|
|
342
|
-
|
|
343
|
-
await gameDatabase.save({
|
|
344
|
-
walletAddress: walletAddress,
|
|
345
|
-
level: 5,
|
|
346
|
-
score: 1000,
|
|
347
|
-
inventory: ['item1', 'item2'],
|
|
348
|
-
});
|
|
94
|
+
#### `init(): Promise<void>`
|
|
349
95
|
|
|
350
|
-
|
|
351
|
-
const saveData = await gameDatabase.loadByWallet(walletAddress);
|
|
352
|
-
```
|
|
96
|
+
Initialize SDK. Must be called after creating SDK instance.
|
|
353
97
|
|
|
354
|
-
|
|
98
|
+
#### `getWalletAddress(): Promise<string | null>`
|
|
355
99
|
|
|
356
|
-
|
|
357
|
-
import { ArcadiaSDK, WalletNotConnectedError, PaymentFailedError } from '@arcadia/game-sdk';
|
|
100
|
+
Get connected wallet address. Returns `null` if not connected.
|
|
358
101
|
|
|
359
|
-
|
|
360
|
-
const arcadia = new ArcadiaSDK({
|
|
361
|
-
gameId: 'my-game-id',
|
|
362
|
-
});
|
|
102
|
+
#### `isWalletConnected(): Promise<boolean>`
|
|
363
103
|
|
|
364
|
-
|
|
104
|
+
Check if wallet is connected.
|
|
365
105
|
|
|
366
|
-
|
|
367
|
-
const walletAddress = await arcadia.getWalletAddress();
|
|
106
|
+
#### `onWalletChange(callback: Function): void`
|
|
368
107
|
|
|
369
|
-
|
|
370
|
-
showMessage('Please connect your wallet in Arcadia to play');
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Load save data
|
|
375
|
-
let saveData = await loadSaveDataByWallet(walletAddress);
|
|
376
|
-
if (!saveData) {
|
|
377
|
-
// First time player
|
|
378
|
-
saveData = createNewSave(walletAddress);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// Handle pay-to-play if required
|
|
382
|
-
if (gameRequiresPayment && !saveData.hasPaid) {
|
|
383
|
-
try {
|
|
384
|
-
const result = await arcadia.payment.payToPlay(0.5, 'SOL');
|
|
385
|
-
saveData.hasPaid = true;
|
|
386
|
-
await saveGameData(walletAddress, saveData);
|
|
387
|
-
startGame();
|
|
388
|
-
} catch (error) {
|
|
389
|
-
if (error instanceof WalletNotConnectedError) {
|
|
390
|
-
showMessage('Please connect your wallet');
|
|
391
|
-
} else if (error instanceof PaymentFailedError) {
|
|
392
|
-
showError('Payment failed: ' + error.message);
|
|
393
|
-
}
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
} else {
|
|
397
|
-
startGame();
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// Listen for wallet changes
|
|
401
|
-
arcadia.onWalletChange((connected, address) => {
|
|
402
|
-
if (!connected) {
|
|
403
|
-
pauseGame();
|
|
404
|
-
showMessage('Wallet disconnected. Please reconnect.');
|
|
405
|
-
}
|
|
406
|
-
});
|
|
108
|
+
Listen for wallet connection changes.
|
|
407
109
|
|
|
408
|
-
|
|
409
|
-
async function buyItem(itemId: string, price: number) {
|
|
410
|
-
try {
|
|
411
|
-
const result = await arcadia.payment.purchaseItem(itemId, price, 'SOL');
|
|
412
|
-
saveData.inventory.push(itemId);
|
|
413
|
-
await saveGameData(walletAddress, saveData);
|
|
414
|
-
showSuccess('Item purchased!');
|
|
415
|
-
} catch (error) {
|
|
416
|
-
showError('Purchase failed: ' + error.message);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
```
|
|
110
|
+
#### `payment.payToPlay(amount, token, txSignature?)`
|
|
420
111
|
|
|
421
|
-
|
|
112
|
+
Pay to play. `txSignature` required for non-iframe mode.
|
|
422
113
|
|
|
423
|
-
|
|
424
|
-
- ES2020 support required
|
|
425
|
-
- postMessage API support
|
|
426
|
-
- No polyfills needed
|
|
114
|
+
#### `payment.purchaseItem(itemId, amount, token, txSignature?)`
|
|
427
115
|
|
|
428
|
-
|
|
116
|
+
Purchase in-game item. `txSignature` required for non-iframe mode.
|
|
429
117
|
|
|
430
|
-
|
|
118
|
+
#### `stats.updatePlaytime(hours, status?)`
|
|
431
119
|
|
|
432
|
-
|
|
433
|
-
import { ArcadiaSDK, SDKConfig, PaymentResult } from '@arcadia/game-sdk';
|
|
120
|
+
Update playtime (non-iframe mode only).
|
|
434
121
|
|
|
435
|
-
|
|
436
|
-
gameId: 'my-game',
|
|
437
|
-
};
|
|
122
|
+
#### `stats.updateOnlineStatus(isOnline)`
|
|
438
123
|
|
|
439
|
-
|
|
440
|
-
const result: PaymentResult = await arcadia.payment.payToPlay(0.5, 'SOL');
|
|
441
|
-
```
|
|
124
|
+
Update online status (non-iframe mode only).
|
|
442
125
|
|
|
443
|
-
##
|
|
126
|
+
## Environment Detection
|
|
444
127
|
|
|
445
|
-
|
|
446
|
-
- All transactions signed in parent window
|
|
447
|
-
- Origin validation for postMessage (configurable)
|
|
448
|
-
- Request timeout prevents hanging
|
|
449
|
-
- No sensitive data in messages
|
|
128
|
+
The SDK automatically detects if it's running in an iframe:
|
|
450
129
|
|
|
451
|
-
|
|
130
|
+
- **Iframe Mode**: Uses `postMessage` for communication
|
|
131
|
+
- **Non-Iframe Mode**: Uses REST API calls (requires `apiBaseURL`)
|
|
452
132
|
|
|
453
|
-
|
|
133
|
+
## Examples
|
|
454
134
|
|
|
455
|
-
|
|
135
|
+
See `/examples` directory for complete examples.
|
|
456
136
|
|
|
457
|
-
|
|
137
|
+
## Documentation
|
|
458
138
|
|
|
139
|
+
Full documentation: https://docs.arcadia.com/sdk
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PaymentRequest, PaymentResponse, WalletAddressResponse } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* API Client for non-iframe environments
|
|
4
|
+
* Handles direct REST API calls when SDK is not running in iframe
|
|
5
|
+
*/
|
|
6
|
+
export declare class APIClient {
|
|
7
|
+
private baseURL;
|
|
8
|
+
private authToken;
|
|
9
|
+
private walletAddress;
|
|
10
|
+
constructor(baseURL?: string);
|
|
11
|
+
/**
|
|
12
|
+
* Detect Arcadia base URL from environment or use default
|
|
13
|
+
*/
|
|
14
|
+
private detectBaseURL;
|
|
15
|
+
/**
|
|
16
|
+
* Set authentication token (from wallet authentication)
|
|
17
|
+
*/
|
|
18
|
+
setAuthToken(token: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Set wallet address (for wallet-based auth)
|
|
21
|
+
*/
|
|
22
|
+
setWalletAddress(address: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Authenticate with wallet
|
|
25
|
+
* Returns auth token for subsequent API calls
|
|
26
|
+
*/
|
|
27
|
+
authenticateWithWallet(walletAddress: string, signature: string, message: string): Promise<{
|
|
28
|
+
token: string;
|
|
29
|
+
user: any;
|
|
30
|
+
profile: any;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Get wallet address (for non-iframe)
|
|
34
|
+
* Requires authentication
|
|
35
|
+
*/
|
|
36
|
+
getWalletAddress(): Promise<WalletAddressResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Send payment request via API
|
|
39
|
+
*/
|
|
40
|
+
sendPaymentRequest(gameId: string, request: PaymentRequest): Promise<PaymentResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Update playtime/stats
|
|
43
|
+
*/
|
|
44
|
+
updatePlaytime(gameId: string, playtimeHours: number, status?: 'playing' | 'owned' | 'completed'): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Update online status
|
|
47
|
+
*/
|
|
48
|
+
updateOnlineStatus(isOnline: boolean, gameId?: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Generic request method
|
|
51
|
+
*/
|
|
52
|
+
private request;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjF;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,aAAa,CAAuB;gBAEhC,OAAO,CAAC,EAAE,MAAM;IAK5B;;OAEG;IACH,OAAO,CAAC,aAAa;IAmBrB;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIvC;;;OAGG;IACG,sBAAsB,CAC1B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IAmBtD;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAuCxD;;OAEG;IACG,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;IAgB3B;;OAEG;IACG,cAAc,CAClB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,WAAW,GACzC,OAAO,CAAC,IAAI,CAAC;IAWhB;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3E;;OAEG;YACW,OAAO;CAgCtB"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Works in iframe environments by communicating with parent window via postMessage.
|
|
6
6
|
*/
|
|
7
7
|
export { ArcadiaSDK } from './sdk';
|
|
8
|
+
export { APIClient } from './api-client';
|
|
8
9
|
export type { SDKConfig, PaymentResult, WalletInfo, MessageType, PaymentRequest, PaymentResponse, InitData, WalletAddressResponse, } from './types';
|
|
9
10
|
export { ArcadiaSDKError, WalletNotConnectedError, PaymentFailedError, TimeoutError, InvalidConfigError, NotInIframeError, InvalidAmountError, InvalidTokenError, } from './errors';
|
|
10
11
|
import { ArcadiaSDK } from './sdk';
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGnC,YAAY,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EACf,QAAQ,EACR,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,eAAe,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,YAAY,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EACf,QAAQ,EACR,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,eAAe,UAAU,CAAC"}
|