@playmos/sdk 0.3.1 โ 0.3.2
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 +33 -20
- package/dist/index.cjs +414 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +379 -129
- package/dist/index.d.ts +379 -129
- package/dist/index.js +410 -44
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**๐งช Beta โ Playmos SDK.** Runs on Base Sepolia **testnet**. The value-movement primitives (escrow / marketplace / transfer) are proven on-chain but **not yet production-hardened**, and nothing is on mainnet. Build and integrate freely against the sandbox; don't route real user funds yet.
|
|
4
4
|
|
|
5
|
-
Stablecoin payments for games on Base. One SDK for in-app purchases (1%), skill-game prize-pool entries (10%, 60/30/10), and agent
|
|
5
|
+
Stablecoin payments for games on Base. One SDK for in-app purchases (1%), skill-game prize-pool entries (10%, 60/30/10), and **in-game economies** (player ยท NPC ยท agent commerce via `transfer()`). USD in, USDC on-chain โ no crypto UX for your players.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -27,21 +27,43 @@ The key comes wired to two demo games: `game_sandbox_iap` (IAP) and `game_sandbo
|
|
|
27
27
|
|
|
28
28
|
### In-app purchase โ `pay()`
|
|
29
29
|
|
|
30
|
+
<!-- snippet:pay -->
|
|
30
31
|
```ts
|
|
31
32
|
import { Playmos } from "@playmos/sdk";
|
|
32
33
|
|
|
33
|
-
//
|
|
34
|
+
// Public sandbox key โ client-safe, like Stripe's pk_test_.
|
|
35
|
+
// No wallet needed: Playmos server-settles the test payment for you.
|
|
34
36
|
const playmos = new Playmos({ apiKey: "pk_test_playmos_sandbox" });
|
|
35
37
|
|
|
36
38
|
const payment = await playmos.pay({
|
|
37
|
-
gameId: "game_sandbox_iap", //
|
|
38
|
-
amount: "
|
|
39
|
+
gameId: "game_sandbox_iap", // public sandbox IAP game โ include it (this key spans IAP + skill)
|
|
40
|
+
amount: "0.99", // USD string โ sandbox server-settle cap $1.00/request
|
|
39
41
|
sku: "gems_500", // your product id
|
|
40
|
-
playerId: "player_abc", // your user id
|
|
42
|
+
playerId: "player_abc", // your opaque user id
|
|
41
43
|
});
|
|
42
44
|
|
|
45
|
+
payment.id; // "pay_โฆ" โ real, server-issued (ULID)
|
|
43
46
|
payment.status; // "confirmed" โ real, on Base Sepolia
|
|
44
|
-
payment.txHash; // 0xโฆ open on sepolia.basescan.org
|
|
47
|
+
payment.txHash; // 0xโฆ โ open on sepolia.basescan.org/tx/{txHash}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Verify before you grant
|
|
51
|
+
|
|
52
|
+
Grant items on a verified confirmation โ never on the client `pay()` return alone.
|
|
53
|
+
|
|
54
|
+
<!-- snippet:verify -->
|
|
55
|
+
```ts
|
|
56
|
+
import { Playmos } from "@playmos/sdk";
|
|
57
|
+
|
|
58
|
+
// Your server โ the secret key lives here, never in a client bundle.
|
|
59
|
+
const server = new Playmos({ apiKey: process.env.PLAYMOS_SECRET! }); // sk_test_โฆ
|
|
60
|
+
|
|
61
|
+
const result = await server.verify(payment.id); // on-chain read โ idempotent, safe to retry
|
|
62
|
+
|
|
63
|
+
// Terminal success is exactly "confirmed" (IAP + entries) โ not "settled" / "succeeded".
|
|
64
|
+
if (result.status === "confirmed") {
|
|
65
|
+
grantItem(result.playerId, result.sku);
|
|
66
|
+
}
|
|
45
67
|
```
|
|
46
68
|
|
|
47
69
|
### Skill-game entry โ `enterRound()`
|
|
@@ -62,7 +84,7 @@ The base value-movement primitive: move USDC from one wallet to another with a c
|
|
|
62
84
|
|
|
63
85
|
```ts
|
|
64
86
|
// NPCโNPC with a 5% fee (Playmos Town P2P). Requires sk_test_ + agents.createWallet first.
|
|
65
|
-
// Full
|
|
87
|
+
// Full walkthrough: see "In-game economies โ the Playmos Town golden path" below.
|
|
66
88
|
// Confirm: status === "settled" && txHash, or await playmos.transfers.wait(id) if settling.
|
|
67
89
|
const t = await playmos.transfer({
|
|
68
90
|
// `from` is OPTIONAL in the sandbox โ omit it and the service uses its server-held signer wallet
|
|
@@ -109,9 +131,9 @@ Fields match the table above (`from` optional โ defaults to the signer; `feeBp
|
|
|
109
131
|
|
|
110
132
|
> Sandbox only (Phase 1a): `transfer` settles server-held NPC/agent wallets on Base Sepolia. The player-signed (EIP-3009) non-custodial path is Phase 1b.
|
|
111
133
|
|
|
112
|
-
###
|
|
134
|
+
### In-game economies โ the Playmos Town golden path
|
|
113
135
|
|
|
114
|
-
|
|
136
|
+
**In-game economies** = commerce between **players, NPCs, and agents** (AI or scripted). The money primitive is **`transfer()`** (entity-agnostic); NPC/agent wallets use **`agents.*`** (API names unchanged). This is the loop the [Playmos Town example](https://github.com/playmos-labs/playmos-sdk/blob/main/docs/examples/playmos-town-sdk.mjs) runs end to end: give each NPC a wallet, fund it, then move value with a per-call fee โ P2P (5%), a monster bounty (0%), a shop sale (100%). Proven on **Base Sepolia** (transfer layer) โ not a claim that a full MMO product is shipped.
|
|
115
137
|
|
|
116
138
|
**Agents need a SECRET test key โ `sk_test_`, not `pk_test_`.** Assigning NPC wallets and transferring *from* an NPC are privileged, server-side actions, so they require an `sk_test_` key kept on **your backend** โ not the public `pk_test_playmos_sandbox`. `pk_test_` runs the no-wallet `pay()` / `enterRound()` demos above; `sk_test_` unlocks `agents.*` and NPC-funded `transfer`.
|
|
117
139
|
|
|
@@ -168,15 +190,6 @@ The full 5-NPC walkthrough โ create โ fund โ P2P / shop / bounty, each con
|
|
|
168
190
|
PLAYMOS_SK_TEST=sk_test_โฆ PLAYMOS_FEE_SINK=0xโฆ node docs/examples/playmos-town-sdk.mjs
|
|
169
191
|
```
|
|
170
192
|
|
|
171
|
-
### Verify before you grant
|
|
172
|
-
|
|
173
|
-
Grant items on a verified confirmation โ never on the client `pay()` return alone.
|
|
174
|
-
|
|
175
|
-
```ts
|
|
176
|
-
const result = await playmos.verify(payment.id); // on-chain read
|
|
177
|
-
if (result.status === "confirmed") grantItem(result.playerId, result.sku);
|
|
178
|
-
```
|
|
179
|
-
|
|
180
193
|
## Mock mode โ offline, deterministic
|
|
181
194
|
|
|
182
195
|
For CI and wiring checks, `mock: true` returns instant, deterministic results with **no network and no chain**. Results carry `mock: true` and use the real status union, so your handling code sees the exact production shape.
|
|
@@ -184,7 +197,7 @@ For CI and wiring checks, `mock: true` returns instant, deterministic results wi
|
|
|
184
197
|
```ts
|
|
185
198
|
const playmos = new Playmos({ apiKey: "pk_test_playmos_sandbox", mock: true });
|
|
186
199
|
const payment = await playmos.pay({
|
|
187
|
-
gameId: "game_sandbox_iap", sku: "gems_100", amount: "
|
|
200
|
+
gameId: "game_sandbox_iap", sku: "gems_100", amount: "0.99", playerId: "player_abc",
|
|
188
201
|
});
|
|
189
202
|
// instant โ payment.status === "confirmed", payment.mock === true
|
|
190
203
|
```
|
|
@@ -229,4 +242,4 @@ The escrow/marketplace resolve endpoints (release/refund/confirm) return a deter
|
|
|
229
242
|
|
|
230
243
|
## Docs
|
|
231
244
|
|
|
232
|
-
Full documentation โ skill games, webhooks, gas, payouts,
|
|
245
|
+
Full documentation โ skill games, webhooks, gas, payouts, in-game economies, and the REST API โ at [playmos.io](https://playmos.io).
|