Prerequisites
- You must already have an ExchangeId. If you do not have one, please refer to Creating an Exchange Task.
SDK Installation
Please refer to SDK Installation for details on how to install the SDK.
Displaying Ads
Once the user clicks on the "Watch Ad" button, execute the following code, for example:
import { TonExchangeAdPopupShow } from 'ton-ai-sdk'
TonExchangeAdPopupShow({
exchangeId: 'your_exchange_id',
onAdClick: (ad) => {
// The user triggered an ad click
// You can issue a reward here
},
onAdError: (error) => {
// An error occurred while the user was watching the ad
// You can choose to do nothing here or handle the error as you see fit
},
})
Tips
Within the onAdClick
function, you can reward users, such as increasing their life points or enhancing a character's abilities.
Tips
Errors may occur due to:
- Network errors when retrieving ads
- Errors during ad playback
- No ads available at the moment
The SDK will display the ad, and the ad effect will look like this:
After the ad countdown ends, various event listeners will trigger, allowing you to issue rewards or perform other actions as desired.