Skip to Content
3. ExamplesExamples

Examples

This page includes common v0.1 (Phase 1) integration examples: product config, purchase, entitlement restore, wallet events, and capability checks.

1) Product Mapping

PHSDK does not allow the client to pass arbitrary amounts; all pricing, token, and chain info come from configuration.

{ "version": "0.1", "products": { "coin_pack_1": { "chainId": 8453, "token": { "address": "0xTOKEN...", "symbol": "USDC", "decimals": 6 }, "payee": "0xPAYEE...", "amount": "1990000", "entitlement": { "id": "coin_pack_1", "type": "consumable", "quantity": 2000 } } } }

Notes:

  • amount is in base units (avoid floating point errors)
  • productId is the only parameter the game needs to pass

2) Purchase

const result = await sdk.pay.purchase({ productId: "coin_pack_1" }); switch (result.status) { case "CONFIRMED": // ✅ Recommended to grant high-value entitlements after confirmation (Phase 1 stores locally) break; case "SUBMITTED": // Transaction broadcasted, waiting for confirmation break; case "REJECTED": // User rejected break; case "FAILED": // Transaction failed (revert / status=0) break; }

3) Query/Restore Entitlements (Local)

const { entitlements } = await sdk.pay.getEntitlements(); console.log(entitlements);

4) Wallet events

sdk.on("wallet.accountsChanged", ({ accounts }) => { console.log("accounts changed", accounts); }); sdk.on("wallet.chainChanged", ({ chainId }) => { console.log("chain changed", chainId); });
const caps = await sdk.env.getCapabilities(); if (!caps.modules.pay.purchase) alert("Payment not supported in this wallet");

6) Copyable sample repo skeleton

See: Sample Repo Skeleton

7) Mock bridge (debug)

If the host only provides WebView + window.ethereum, inject the mock bridge script first:

<script src="/path/to/bridge.mock.js"></script>