---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.4
alternate:
  - https://yandex.com/dev/games/doc/en/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/hi/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/ko/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/ru/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/tr/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/vi/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/zh/sdk/cocos/ysdk.md
  - href: en/sdk/cocos/ysdk.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/en/llms.txt

# Yandex Games SDK API

<!-- source: en/_includes/script-common.md -->
<!-- source: en/_includes/script/index-js.md -->

<!-- endsource: en/_includes/script/index-js.md -->

<!-- source: en/_includes/script/requirements-js.md -->

<!-- endsource: en/_includes/script/requirements-js.md -->

<!-- source: en/_includes/script/image-modal-js.md -->

<!-- endsource: en/_includes/script/image-modal-js.md -->
<!-- endsource: en/_includes/script-common.md -->

After installing the plugin, you will find the `ysdk` object, which is a typed equivalent of the [same-named object from the Yandex Games SDK](https://yandex.com/dev/games/doc/en/sdk/sdk-game-events.md). It allows you to access all methods of the SDK.

Here is an example of how to use [environment variables](https://yandex.com/dev/games/doc/en/sdk/sdk-environment.md) from the Yandex Games SDK.

```tsx showLineNumbers
import { Component } from "cc";
import { ysdk } from "db://yandex-games-sdk/ysdk";
const { ccclass, property } = _decorator;

@ccclass("YourGameComponent")
export class YourGameComponent extends Component {
  start() {
    console.debug(`App ID: ${ysdk.environment.app.id}`);
    console.debug(`User Language: ${ysdk.environment.i18n.lang}`);
    console.debug(`URL Payload: ${ysdk.environment.payload}`);
  }

  update(deltaTime: number) {}
}
```

## Component for Displaying Ads {#ads-display-component}

For example, let's create a component for a button that launches a rewarded video ad.

Additionally, we will define a method `onReward()` and pass it as a callback for the method `ysdk.adv.showRewardedVideo()`, to implement the event logic for receiving a reward.

```tsx showLineNumbers
import { _decorator, Button, Component } from "cc";
import { ysdk } from "db://yandex-games-sdk/ysdk";
const { ccclass, property, requireComponent } = _decorator;

@ccclass("RewardADButton")
@requireComponent(Button)
export class RewardADButton extends Component {
  start() {
    this.node.on("click", this.onClick.bind(this));
  }

  onClick() {
    const callbacks = {
      onRewarded: this.onReward.bind(this),
    };

    ysdk.adv.showRewardedVideo({ callbacks });
  }

  onReward() {
    // Reward the user.
  }
}
```

When you click on a button with this component on the Yandex platform, you will see an advertisement. For simplified testing, refer to the [Testing](https://yandex.com/dev/games/doc/en/sdk/cocos/testing.md) section.


---


<!-- source: en/_includes/button-git.md -->
<a href="https://github.com/yandex-games-plugins/cocos">
  <span class="button">Repository</span>
</a>
<!-- endsource: en/_includes/button-git.md -->
