# Rewarded ads that pay

> Offer a video for a reward, check on your server that it was watched by that player, and pay once per video. From the Lia developer docs: https://docs.lialabs.org/guides/rewarded-ads

The page plays the video and gets an `adId`. Your server checks the `adId` with Lia, then gives the reward, once.

## In your page

```js title="game.js"
async function secondChance() {
  const result = await Lia.showRewardedAd({
    onState: function (state) {
      if (state === "loading") pauseGame();
    },
  });
  if (!result.watched) {
    if (result.reason === "no_ad") Lia.toast("No video right now. Try again soon.");
    return endRun();
  }
  const { ok } = await api("/api/second-chance", { adId: result.adId });
  ok ? continueRun() : endRun();
}
```

Offer the video with your own button ("Watch a video to keep going"). People choose rewarded videos, so Lia doesn't pace them.

## On your server

```js title="server.js"
app.post("/api/second-chance", async (req, res) => {
  const playerId = await playerFrom(req.body.session);
  if (!playerId) return res.status(401).end();

  let ad;
  try {
    ad = await lia("POST", "/ads/verify", { adId: req.body.adId });
  } catch {
    return res.json({ ok: false });
  }
  if (!ad.watched || ad.playerId !== playerId) return res.json({ ok: false });

  // Once per video: a second request with the same adId gets nothing more.
  const first = await db.useOnce(`ad:${ad.adId}`);
  if (!first) return res.json({ ok: false });

  await db.grantSecondChance(playerId);
  res.json({ ok: true });
});
```

## Paying $LIA for a video

If the reward is $LIA from your [pool](/concepts/reward-pools), the reward key does the "once" for you:

```js
await lia("POST", "/rewards", { playerId, amount: 0.5, key: `ad:${ad.adId}`, reason: "Watched a video" });
```

## Between rounds

Interstitials need no server and give nothing. Ask at each natural break and let Lia pace them:

```js
async function nextRound() {
  await Lia.showInterstitialAd(); // often answers "too_soon" at once, and that's fine
  startRound();
}
```

A rewarded interstitial sits between the two: Lia offers it with Watch and Skip, and a watched one has an `adId` to check like a rewarded video.

## Good to know

- `/ads/verify` says `watched: true` for interstitials that were shown, too. Only reward `adId`s your page got from a rewarded format with `watched: true`.
- If a video stops partway because of a problem on the phone, Lia counts it as watched, so nobody loses a reward over a broken ad.
- Pause your game and its sound on `"loading"`; your page also hears `pause` and `resume` around the video.
