@suigar/sdk 2.0.0-beta.2 → 2.0.0-beta.4
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/CHANGELOG.md +33 -1
- package/README.md +233 -46
- package/dist/chunk-W3WZ2BHO.js +310 -0
- package/dist/games-nFnPbPuK.d.cts +84 -0
- package/dist/games-nFnPbPuK.d.ts +84 -0
- package/dist/games.cjs +2 -0
- package/dist/games.d.cts +1 -0
- package/dist/games.d.ts +1 -0
- package/dist/games.js +1 -0
- package/dist/index-jwSXA8q3.d.cts +25 -0
- package/dist/index-jwSXA8q3.d.ts +25 -0
- package/dist/index.cjs +269 -97
- package/dist/index.d.cts +115 -109
- package/dist/index.d.ts +115 -109
- package/dist/index.js +229 -231
- package/dist/utils.cjs +208 -0
- package/dist/utils.d.cts +79 -0
- package/dist/utils.d.ts +79 -0
- package/dist/utils.js +1 -0
- package/package.json +29 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
# @suigar/sdk
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6daa819: Add BCS parser helpers and a Next.js game integration example app.
|
|
8
|
+
- expose parser helpers through `@suigar/sdk/utils`
|
|
9
|
+
- add `parseGameDetails` for decoding `BetResultEvent.game_details`
|
|
10
|
+
- document generated BCS event decoding and game detail parsing guidance
|
|
11
|
+
- add a testnet-only `examples/game-integration` app for standard and PvP Suigar transactions
|
|
12
|
+
- integrate Mysten dApp Kit wallet connection, signing, and execution
|
|
13
|
+
- add live transaction code previews and shared decoded event logging with SDK parser helpers
|
|
14
|
+
- add Suigar-themed responsive UI, supported coin selection, and human-readable stake handling
|
|
15
|
+
- update PvP coinflip join so callers only provide `gameId` and the SDK derives the join stake while using the configured price info object id
|
|
16
|
+
|
|
17
|
+
- b89d0b4: Add a public `@suigar/sdk/games` export subpath for shared game option types, and export `SuigarClient` from the package root.
|
|
18
|
+
- bf1f71b: Add `registryIds` to `SuigarConfig` and resolve it from the network config registry map.
|
|
19
|
+
|
|
20
|
+
Document the PvP coinflip runtime helpers more clearly by describing
|
|
21
|
+
registry-backed unresolved game discovery through `getPvPCoinflipGames()` and
|
|
22
|
+
the normalized live-game lookup behavior of `resolvePvPConflipGame()`.
|
|
23
|
+
|
|
24
|
+
- 4861f55: Add public utility exports for shared scaling constants in `@suigar/sdk/utils`, including `RANGE_POINT_LIMIT` and `DEFAULT_RANGE_SCALE`. Update the SDK example app and documentation to use the exported constants and document limbo/range scaling behavior more clearly.
|
|
25
|
+
|
|
26
|
+
## 2.0.0-beta.3
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- e1cdedc: Improve public transaction builder typings and refresh Sui 2.0+ integration guidance around the gRPC client.
|
|
31
|
+
- Fix exported transaction option types so `BuildGameOptions` and `BuildPvPGameOptions` no longer require the internal `config` field
|
|
32
|
+
- Update installation and integration documentation for Sui 2.0+ by switching examples to `SuiGrpcClient`, clarifying required peer dependencies, and aligning transaction-result examples with the current client API.
|
|
33
|
+
|
|
3
34
|
## 2.0.0-beta.2
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
6
37
|
|
|
7
|
-
- 128cb6c: -
|
|
38
|
+
- 128cb6c: Make SDK configuration network-resolved and expose runtime config inspection through the client extension.
|
|
39
|
+
- `suigar()` now only accepts the extension `name`.
|
|
8
40
|
- The SDK now validates the connected client network and supports `mainnet` and `testnet`.
|
|
9
41
|
- Added `client.suigar.getConfig()` to inspect the resolved network config at runtime.
|
|
10
42
|
- Exported the `SuiNetwork` type and `resolveGamePackageId()` helper.
|
package/README.md
CHANGED
|
@@ -5,32 +5,77 @@ TypeScript SDK for building Suigar v2 game transactions on Sui.
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @suigar/sdk
|
|
8
|
+
npm install --save @suigar/sdk @mysten/sui @mysten/bcs
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
Runtime requirements:
|
|
12
12
|
|
|
13
13
|
- Node.js `>=22`
|
|
14
|
-
-
|
|
14
|
+
- ESM project configuration (`"type": "module"`)
|
|
15
|
+
- `@mysten/sui` v2
|
|
16
|
+
- `@mysten/bcs` v2
|
|
17
|
+
|
|
18
|
+
This SDK targets Sui TypeScript SDK 2.0+ only. Follow the official [Sui 2.0 migration guide](https://sdk.mystenlabs.com/sui/migrations/sui-2.0) if your app still uses the pre-2.0 client API.
|
|
15
19
|
|
|
16
20
|
## What This Package Exposes
|
|
17
21
|
|
|
18
|
-
The package
|
|
22
|
+
The package ships three public entrypoints:
|
|
23
|
+
|
|
24
|
+
- `@suigar/sdk` for the extension factory and runtime client class
|
|
25
|
+
- `@suigar/sdk/games` for game-specific public types
|
|
26
|
+
- `@suigar/sdk/utils` for public parser, constants, and numeric helpers
|
|
27
|
+
|
|
28
|
+
The package root exposes the extension factory and client class:
|
|
19
29
|
|
|
20
30
|
```ts
|
|
21
|
-
import { suigar } from '@suigar/sdk';
|
|
31
|
+
import { suigar, SuigarClient } from '@suigar/sdk';
|
|
22
32
|
```
|
|
23
33
|
|
|
24
34
|
It does not export the individual transaction builders from the package root.
|
|
25
|
-
|
|
35
|
+
Those stay on the registered extension instance under `client.suigar.tx`.
|
|
36
|
+
|
|
37
|
+
Utility exports are available from the utils subpath:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import {
|
|
41
|
+
DEFAULT_GAS_BUDGET_MIST,
|
|
42
|
+
DEFAULT_LIMBO_MULTIPLIER_SCALE,
|
|
43
|
+
DEFAULT_RANGE_SCALE,
|
|
44
|
+
RANGE_POINT_LIMIT,
|
|
45
|
+
parseFloat,
|
|
46
|
+
parseGameDetails,
|
|
47
|
+
parseI64,
|
|
48
|
+
toBigIntAmount,
|
|
49
|
+
toU8Number,
|
|
50
|
+
} from '@suigar/sdk/utils';
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Game-specific type exports are available from the dedicated `games` subpath:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import type {
|
|
57
|
+
BuildCoinflipTransactionOptions,
|
|
58
|
+
CoinSide,
|
|
59
|
+
} from '@suigar/sdk/games';
|
|
60
|
+
import type {
|
|
61
|
+
BuildCreatePvPCoinflipTransactionOptions,
|
|
62
|
+
PvPCoinflipAction,
|
|
63
|
+
} from '@suigar/sdk/games';
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Current game-type subpath exports:
|
|
67
|
+
|
|
68
|
+
- `@suigar/sdk/games`: `CoinSide`, `PvPCoinflipAction`, `BuildCoinflipTransactionOptions`, `BuildLimboTransactionOptions`, `BuildPlinkoTransactionOptions`, `BuildRangeTransactionOptions`, `BuildWheelTransactionOptions`, `BuildCreatePvPCoinflipTransactionOptions`, `BuildJoinPvPCoinflipTransactionOptions`, `BuildCancelPvPCoinflipTransactionOptions`
|
|
26
69
|
|
|
27
70
|
What you actually use at runtime is the registered extension instance:
|
|
28
71
|
|
|
29
72
|
```ts
|
|
30
|
-
const client = new
|
|
73
|
+
const client = new SuiGrpcClient({ baseUrl, network }).$extend(suigar());
|
|
31
74
|
|
|
32
75
|
client.suigar.serializeTransactionToBase64(...);
|
|
33
76
|
client.suigar.getConfig();
|
|
77
|
+
client.suigar.getPvPCoinflipGames(...);
|
|
78
|
+
client.suigar.resolvePvPConflipGame(...);
|
|
34
79
|
client.suigar.bcs;
|
|
35
80
|
client.suigar.tx;
|
|
36
81
|
```
|
|
@@ -38,11 +83,12 @@ client.suigar.tx;
|
|
|
38
83
|
## Quick Start
|
|
39
84
|
|
|
40
85
|
```ts
|
|
41
|
-
import {
|
|
86
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
42
87
|
import { suigar } from '@suigar/sdk';
|
|
43
88
|
|
|
44
|
-
const client = new
|
|
45
|
-
|
|
89
|
+
const client = new SuiGrpcClient({
|
|
90
|
+
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
91
|
+
network: 'testnet',
|
|
46
92
|
}).$extend(suigar());
|
|
47
93
|
|
|
48
94
|
const tx = client.suigar.tx.createBetTransaction('coinflip', {
|
|
@@ -61,19 +107,33 @@ const base64 = await client.suigar.serializeTransactionToBase64(tx);
|
|
|
61
107
|
|
|
62
108
|
Creates a named Sui client extension. By default, it registers under `client.suigar`.
|
|
63
109
|
|
|
110
|
+
### Partner Setup
|
|
111
|
+
|
|
112
|
+
> [!IMPORTANT]
|
|
113
|
+
> `partner` is the partner wallet address. Configure it once when you
|
|
114
|
+
> register the extension so the SDK can append that wallet address to supported
|
|
115
|
+
> bet metadata automatically.
|
|
116
|
+
|
|
64
117
|
```ts
|
|
65
|
-
const client = new
|
|
118
|
+
const client = new SuiGrpcClient({ baseUrl, network }).$extend(
|
|
119
|
+
suigar({ partner: '0xpartner_wallet_address' }),
|
|
120
|
+
);
|
|
66
121
|
|
|
67
122
|
client.suigar;
|
|
68
123
|
```
|
|
69
124
|
|
|
125
|
+
Do not pass a partner slug, label, or display name here. Use the wallet
|
|
126
|
+
address that should receive partner attribution onchain.
|
|
127
|
+
|
|
70
128
|
You can rename the extension:
|
|
71
129
|
|
|
72
130
|
```ts
|
|
73
|
-
const client = new
|
|
131
|
+
const client = new SuiGrpcClient({ baseUrl, network }).$extend(
|
|
132
|
+
suigar({ name: 'games' }),
|
|
133
|
+
);
|
|
74
134
|
|
|
75
|
-
client.
|
|
76
|
-
client.
|
|
135
|
+
client.games.tx;
|
|
136
|
+
client.games.bcs;
|
|
77
137
|
```
|
|
78
138
|
|
|
79
139
|
## Config
|
|
@@ -83,19 +143,27 @@ client.casino.bcs;
|
|
|
83
143
|
- internal package ids by network
|
|
84
144
|
- internal supported coin types by network
|
|
85
145
|
- internal price info object ids by network
|
|
86
|
-
- the connected
|
|
146
|
+
- the connected client network
|
|
87
147
|
- the extension name
|
|
88
148
|
|
|
89
149
|
Supported override areas:
|
|
90
150
|
|
|
91
151
|
- `name`
|
|
152
|
+
- `partner`
|
|
153
|
+
|
|
154
|
+
If `partner` is configured, the SDK automatically writes that partner wallet
|
|
155
|
+
address into the onchain metadata vec-map. Transaction builder options may also
|
|
156
|
+
include `metadata`, but reserved keys such as `partner` and `referrer` are
|
|
157
|
+
ignored with a warning when provided manually.
|
|
92
158
|
|
|
93
159
|
## Runtime Surface
|
|
94
160
|
|
|
95
|
-
The registered extension instance exposes
|
|
161
|
+
The registered extension instance exposes the main runtime surface:
|
|
96
162
|
|
|
97
163
|
- `getConfig()`
|
|
98
164
|
- `serializeTransactionToBase64(transaction, options?)`
|
|
165
|
+
- `getPvPCoinflipGames(options?)`
|
|
166
|
+
- `resolvePvPConflipGame(gameId)`
|
|
99
167
|
- `bcs`
|
|
100
168
|
- `tx`
|
|
101
169
|
|
|
@@ -109,6 +177,7 @@ resolved package ids or supported coin mappings for the active client network.
|
|
|
109
177
|
It includes:
|
|
110
178
|
|
|
111
179
|
- `packageIds`
|
|
180
|
+
- `registryIds`
|
|
112
181
|
- `coinTypes`
|
|
113
182
|
- `priceInfoObjectIds`
|
|
114
183
|
|
|
@@ -127,6 +196,58 @@ Use this when you need a transport-safe payload for a wallet, API, or external s
|
|
|
127
196
|
const base64 = await client.suigar.serializeTransactionToBase64(tx);
|
|
128
197
|
```
|
|
129
198
|
|
|
199
|
+
### `getPvPCoinflipGames(options?)`
|
|
200
|
+
|
|
201
|
+
Lists unresolved PvP coinflip games from the configured PvP registry.
|
|
202
|
+
|
|
203
|
+
This reads the registry dynamic fields for the active network and resolves each
|
|
204
|
+
entry into parsed game state through `resolvePvPConflipGame()`. Registry
|
|
205
|
+
membership is the unresolved-state signal: once a match is joined and resolved,
|
|
206
|
+
the Move flow removes it from the registry and deletes the live `Game` object.
|
|
207
|
+
|
|
208
|
+
Use this when a product needs the current set of open PvP coinflip matches for
|
|
209
|
+
browsing or lobby views.
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
const games = await client.suigar.getPvPCoinflipGames({ limit: 20 });
|
|
213
|
+
|
|
214
|
+
for (const game of games) {
|
|
215
|
+
console.log(game.id);
|
|
216
|
+
console.log(game.coinType);
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### `resolvePvPConflipGame(gameId)`
|
|
221
|
+
|
|
222
|
+
Fetches a PvP coinflip game object from chain and parses it into the SDK's
|
|
223
|
+
normalized runtime shape.
|
|
224
|
+
|
|
225
|
+
This requires the object's `content`, decodes it with the generated
|
|
226
|
+
`PvPCoinflipGame` parser, and normalizes the generic coin type into a standard
|
|
227
|
+
struct tag string.
|
|
228
|
+
|
|
229
|
+
Use this when a product needs the live onchain match state for a specific
|
|
230
|
+
pending match before rendering join or cancel actions, or inspecting the stake
|
|
231
|
+
and privacy flag for a game.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
const game = await client.suigar.resolvePvPConflipGame('0xGAME_ID');
|
|
235
|
+
|
|
236
|
+
console.log(game.creator);
|
|
237
|
+
console.log(game.coinType);
|
|
238
|
+
console.log(game.stake_per_player);
|
|
239
|
+
console.log(game.is_private);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
> [!NOTE]
|
|
243
|
+
>
|
|
244
|
+
> - it throws if the object response does not include decodable `content`
|
|
245
|
+
> - the PvP join builder uses this internally to derive the required join stake
|
|
246
|
+
> - after a game is joined and resolved, the live `Game` object is removed from the registry and deleted, so inspect `PvPCoinflipGameResolved` to read the final result
|
|
247
|
+
|
|
248
|
+
> [!TIP]
|
|
249
|
+
> Prefer this helper over manual object parsing when you only need the parsed state for a live PvP game object.
|
|
250
|
+
|
|
130
251
|
## `tx`
|
|
131
252
|
|
|
132
253
|
Transaction builders live under `client.suigar.tx`.
|
|
@@ -169,6 +290,8 @@ Shared behavior:
|
|
|
169
290
|
- `betCount` defaults to `1`
|
|
170
291
|
- `sender` overrides the transaction sender
|
|
171
292
|
- `metadata` is encoded into `keys` and `values` byte arrays
|
|
293
|
+
- `partner` configured via `suigar({ partner })` is appended automatically to metadata as the partner wallet address
|
|
294
|
+
- `metadata.partner` and `metadata.referrer` are reserved and ignored with a warning
|
|
172
295
|
- the SDK resolves the price info object from the configured supported-coin mapping
|
|
173
296
|
- the reward object is transferred back to `owner`
|
|
174
297
|
|
|
@@ -194,17 +317,25 @@ const rangeTx = client.suigar.tx.createBetTransaction('range', {
|
|
|
194
317
|
owner: '0x123',
|
|
195
318
|
coinType: '0x2::sui::SUI',
|
|
196
319
|
stake: 1_000_000_000n,
|
|
197
|
-
leftPoint:
|
|
198
|
-
rightPoint:
|
|
320
|
+
leftPoint: 25,
|
|
321
|
+
rightPoint: 75,
|
|
199
322
|
outOfRange: false,
|
|
200
323
|
});
|
|
201
324
|
```
|
|
202
325
|
|
|
203
|
-
|
|
326
|
+
> [!NOTE]
|
|
327
|
+
>
|
|
328
|
+
> - limbo converts `targetMultiplier` with `Math.round(targetMultiplier * scale)`
|
|
329
|
+
> - with the default limbo scale `100`, exposed as `DEFAULT_LIMBO_MULTIPLIER_SCALE`, a target multiplier of `2.5` becomes `250` onchain
|
|
330
|
+
> - range converts each point with `Math.round(value * scale)`
|
|
331
|
+
> - range points are bounded by the contract limit exposed as `RANGE_POINT_LIMIT`
|
|
332
|
+
> - with the default range scale `1_000_000`, exposed as `DEFAULT_RANGE_SCALE`, valid UI values are `0` to `100`
|
|
333
|
+
> - plinko and wheel `configId` must fit in `u8`
|
|
204
334
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
-
|
|
335
|
+
> [!TIP]
|
|
336
|
+
>
|
|
337
|
+
> - if you set `scale` to `10_000_000`, valid UI values become `0` to `10`
|
|
338
|
+
> - do not pre-scale range points before passing them to the SDK; pass the human value and let the SDK scale it once
|
|
208
339
|
|
|
209
340
|
### PvP Coinflip
|
|
210
341
|
|
|
@@ -233,8 +364,6 @@ const tx = client.suigar.tx.createPvPCoinflipTransaction('join', {
|
|
|
233
364
|
owner: '0x123',
|
|
234
365
|
coinType: '0x2::sui::SUI',
|
|
235
366
|
gameId: '0xGAME_ID',
|
|
236
|
-
extraObjectId: '0xEXTRA_OBJECT_ID',
|
|
237
|
-
stake: 1_000_000_000n,
|
|
238
367
|
});
|
|
239
368
|
```
|
|
240
369
|
|
|
@@ -248,11 +377,14 @@ const tx = client.suigar.tx.createPvPCoinflipTransaction('cancel', {
|
|
|
248
377
|
});
|
|
249
378
|
```
|
|
250
379
|
|
|
380
|
+
Join derives the stake from `gameId` and uses the configured price info object
|
|
381
|
+
id for `coinType`.
|
|
382
|
+
|
|
251
383
|
PvP shared options:
|
|
252
384
|
|
|
253
385
|
- `owner: string`
|
|
254
386
|
- `coinType: string`
|
|
255
|
-
- `metadata?:
|
|
387
|
+
- `metadata?: Record<string, string | number | boolean | bigint | Uint8Array | number[] | null | undefined>`
|
|
256
388
|
- `gasBudget?: number | bigint`
|
|
257
389
|
- `sender?: string`
|
|
258
390
|
- `allowGasCoinShortcut?: boolean`
|
|
@@ -260,7 +392,7 @@ PvP shared options:
|
|
|
260
392
|
Action-specific options:
|
|
261
393
|
|
|
262
394
|
- `create`: `stake`, `side`, `isPrivate?`
|
|
263
|
-
- `join`: `gameId
|
|
395
|
+
- `join`: `gameId`
|
|
264
396
|
- `cancel`: `gameId`
|
|
265
397
|
|
|
266
398
|
## `bcs`
|
|
@@ -269,12 +401,41 @@ BCS helpers live under `client.suigar.bcs`.
|
|
|
269
401
|
|
|
270
402
|
Current exposed helpers:
|
|
271
403
|
|
|
404
|
+
- `PvPCoinflipGame`
|
|
272
405
|
- `BetResultEvent`
|
|
273
406
|
- `PvPCoinflipGameCreated`
|
|
274
407
|
- `PvPCoinflipGameResolved`
|
|
275
408
|
- `PvPCoinflipGameCancelled`
|
|
276
409
|
|
|
277
|
-
These are generated Move event decoders. Use them to parse Suigar event payloads from transaction results.
|
|
410
|
+
These are generated Move event decoders. Use them to parse Suigar event payloads from transaction results. The `@suigar/sdk/utils` subpath also exposes parser helpers for generated BCS values:
|
|
411
|
+
|
|
412
|
+
- `PvPCoinflipGame` parses a PvP coinflip game object's `content`
|
|
413
|
+
- `parseI64(float.exp)` converts a generated Move `i64` exponent to a JavaScript number
|
|
414
|
+
- `parseFloat(float)` converts a generated Move `Float` struct to a JavaScript number
|
|
415
|
+
- `parseGameDetails(game_details)` decodes `BetResultEvent.game_details` entries into the expected string, number, and boolean values
|
|
416
|
+
|
|
417
|
+
### Parse PvP Coinflip Game Object Data
|
|
418
|
+
|
|
419
|
+
Use the BCS helper directly when you already fetched the object with `content`:
|
|
420
|
+
|
|
421
|
+
```ts
|
|
422
|
+
const { object } = await client.core.getObject({
|
|
423
|
+
objectId: '0xGAME_ID',
|
|
424
|
+
include: { content: true },
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
if (!object.content) {
|
|
428
|
+
throw new Error('Missing game content');
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const parsed = client.suigar.bcs.PvPCoinflipGame.parse(object.content);
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
If you only need the parsed game object, prefer the convenience method:
|
|
435
|
+
|
|
436
|
+
```ts
|
|
437
|
+
const parsed = await client.suigar.resolvePvPConflipGame('0xGAME_ID');
|
|
438
|
+
```
|
|
278
439
|
|
|
279
440
|
### Parse Standard Bet Result Data
|
|
280
441
|
|
|
@@ -295,14 +456,13 @@ const finalResult = await client.core.waitForTransaction({
|
|
|
295
456
|
},
|
|
296
457
|
});
|
|
297
458
|
|
|
298
|
-
if (finalResult
|
|
299
|
-
|
|
300
|
-
} else if (finalResult.FailedTransaction) {
|
|
301
|
-
throw new Error(finalResult.FailedTransaction.status.error.message);
|
|
459
|
+
if (finalResult.$kind === 'FailedTransaction') {
|
|
460
|
+
throw new Error(finalResult.FailedTransaction.status.error?.message);
|
|
302
461
|
}
|
|
303
462
|
|
|
304
|
-
|
|
305
|
-
|
|
463
|
+
console.log(finalResult.Transaction.digest);
|
|
464
|
+
|
|
465
|
+
const transactionResult = finalResult.Transaction;
|
|
306
466
|
|
|
307
467
|
const betResults = [];
|
|
308
468
|
|
|
@@ -327,26 +487,32 @@ Parsed fields include:
|
|
|
327
487
|
- `game_details`
|
|
328
488
|
- `metadata`
|
|
329
489
|
|
|
330
|
-
`game_details` and `metadata` decode as `VecMap<string, vector<u8>>`-shaped data, so values come back as byte arrays.
|
|
490
|
+
`game_details` and `metadata` decode as `VecMap<string, vector<u8>>`-shaped data, so values come back as byte arrays. Use `parseGameDetails` from `@suigar/sdk/utils` to decode `game_details` with the SDK's known game-detail schemas.
|
|
331
491
|
|
|
332
492
|
```ts
|
|
333
|
-
|
|
493
|
+
import { parseGameDetails } from '@suigar/sdk/utils';
|
|
334
494
|
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
key,
|
|
338
|
-
textDecoder.decode(new Uint8Array(value)),
|
|
339
|
-
]),
|
|
340
|
-
);
|
|
495
|
+
const decoded = client.suigar.bcs.BetResultEvent.parse(event.bcs);
|
|
496
|
+
const gameDetails = parseGameDetails(decoded.game_details);
|
|
341
497
|
```
|
|
342
498
|
|
|
343
|
-
|
|
499
|
+
`parseGameDetails` preserves the onchain keys and only changes the value representation. For example, coinflip details keep keys such as `player_bet` and `coin_outcome`; range details keep keys such as `roll_value`, `win`, and `payout_multiplier`.
|
|
500
|
+
|
|
501
|
+
When the extension is configured with `partner`, decoded event `metadata` will
|
|
502
|
+
contain that partner wallet address under the `partner` entry.
|
|
503
|
+
|
|
504
|
+
> [!IMPORTANT]
|
|
505
|
+
>
|
|
506
|
+
> - execute or wait for the transaction with `include: { events: true }`
|
|
507
|
+
> - unwrap the core API union with `result.$kind`, `result.Transaction`, and `result.FailedTransaction`
|
|
508
|
+
> - parse emitted events from the unwrapped transaction result
|
|
509
|
+
> - use `event.bcs` for consistent decoding across transports
|
|
510
|
+
> - use `parseGameDetails(decoded.game_details)` instead of hand-decoding standard game detail byte arrays
|
|
344
511
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
-
|
|
348
|
-
-
|
|
349
|
-
- these helpers decode the event payload itself, not a full transaction response
|
|
512
|
+
> [!TIP]
|
|
513
|
+
>
|
|
514
|
+
> - `waitForTransaction({ result, include: { effects: true, events: true } })` is useful when you want the finalized transaction result before decoding
|
|
515
|
+
> - these helpers decode the event payload itself, not a full transaction response
|
|
350
516
|
|
|
351
517
|
### Parse PvP Coinflip Event Data
|
|
352
518
|
|
|
@@ -363,3 +529,24 @@ npm run build
|
|
|
363
529
|
npm run typecheck
|
|
364
530
|
npm test
|
|
365
531
|
```
|
|
532
|
+
|
|
533
|
+
## Example App
|
|
534
|
+
|
|
535
|
+
This repository now includes a Next.js integration example in [examples/game-integration](/Users/lucas/Documents/Github/suigar-sdk/examples/game-integration).
|
|
536
|
+
|
|
537
|
+
It demonstrates:
|
|
538
|
+
|
|
539
|
+
- standard game transactions through `client.suigar.tx.createBetTransaction(...)`
|
|
540
|
+
- PvP coinflip create, join, and cancel flows through `client.suigar.tx.createPvPCoinflipTransaction(...)`, exposed in the example through a PvP game selector ready for future PvP games
|
|
541
|
+
- wallet connection and execution with `@mysten/dapp-kit-core` and `@mysten/dapp-kit-react`
|
|
542
|
+
- supported coin selection from `client.suigar.getConfig()`
|
|
543
|
+
- connected-wallet balance display for each supported coin in the example app
|
|
544
|
+
- decoding `BetResultEvent` and PvP events into a persistent event log
|
|
545
|
+
- parsing `BetResultEvent.game_details` with `parseGameDetails`
|
|
546
|
+
|
|
547
|
+
Run it from the repo root with:
|
|
548
|
+
|
|
549
|
+
```bash
|
|
550
|
+
npm --prefix examples/game-integration install
|
|
551
|
+
npm --prefix examples/game-integration run dev
|
|
552
|
+
```
|