# Usage

After [setup](https://docs.play.fun/build-on-play.fun/play-fun-sdk/vanilla-js-sdk/setup), the SDK is ready to use. Here's the core workflow:

## Points Flow

```js
// 1. Add points during gameplay (accumulated locally, flushed incrementally)
sdk.addPoints(10);

// 2. End the game and save points (commits all accumulated points)
await sdk.endGame();
```

**Important:**

* `endGame()` takes no parameters. It saves all points accumulated via `addPoints()`. `savePoints()` is an alias for `endGame()`.
* **This method opens a gameplay-blocking modal** that shows a loading screen, then either a success screen (with a points boost prompt) or an error screen. The game should treat this as an "end of round" action — **do not call it during active gameplay**, as the modal will overlay and interrupt the player's session.
* If the player isn't logged in, the SDK automatically triggers a login modal first, then saves after authentication completes.
* Rate-limited to once every 5 seconds.

## Reading Points

```js
const { points, activeMultiplier } = await sdk.getPoints();
console.log(`Today's points: ${points}, multiplier: ${activeMultiplier}x`);
```

## Rewards

```js
// List available rewards
const rewards = await sdk.listUserRewards();

// Claim rewards for specific token addresses
await sdk.claimRewards(['token-mint-address']);
```

## UI Controls

```js
sdk.showPoints(); // Show the points widget
sdk.hidePoints(); // Hide the points widget
sdk.setTheme('dark'); // Change theme: 'light', 'dark', or 'system'
```

## Events

```js
sdk.on('SavePointsSuccess', () => {
  console.log('Points saved!');
});

sdk.on('SavePointsFailed', () => {
  console.log('Failed to save points');
});

sdk.on('ClaimSuccess', () => {
  console.log('Rewards claimed!');
});

// Catch all events
sdk.onAll((eventName, data) => {
  console.log(`Event: ${eventName}`, data);
});
```

See the [full SDK reference](https://docs.play.fun/build-on-play.fun/play-fun-sdk) for all available methods and events.
