Quick Start Guide: TypeScript¶
Initialize SDK¶
-
Install the Balancy SDK packages:
npm install --save @balancy/core@latest npm install --save @balancy/utils@latest -
Download React example components:
- BalancySimpleIntegration.tsx - A simple integration example that initializes the SDK and displays active events/offers
- BalancyMainUI.tsx - UI component for displaying Balancy elements with icons and timers
-
Import and use in your project:
import { BalancySimpleIntegration, SimpleBalancyConfig } from './components/BalancySimpleIntegration'; import { Environment } from '@balancy/core'; const config: SimpleBalancyConfig = { apiGameId: 'your_game_id', publicKey: 'your_public_key', environment: Environment.Development }; function App() { return ( <div> {/* Your app content */} <BalancySimpleIntegration config={config} onReady={() => console.log('Balancy is ready!')} onError={(error) => console.error('Balancy error:', error)} /> </div> ); } -
Launch your React app:
After Balancy loads, you'll see icons for all active offers and events. Click any icon to open its associated view. A red "Reset" button in the top-right corner allows you to reset Balancy profiles for testing.

Payments¶
The example includes a preparePayments() function that sets up the mandatory Balancy payment callbacks:
function createTestPaymentInfo(price: SmartObjectsPrice): BalancyPaymentInfo {
const orderId = generateGuid();
const productId = price.product?.productId || "";
const productPrice = price.product?.price || 0;
const paymentInfo: BalancyPaymentInfo = {
price: productPrice,
currency: "USD",
orderId: orderId,
productId: productId,
receipt: `<receipt>` // Placeholder for receipt
};
// Below is the testing receipt, it's not designed for production
paymentInfo.receipt = JSON.stringify({
Payload: JSON.stringify({
json: JSON.stringify({
orderId: paymentInfo.orderId,
productId: paymentInfo.productId
}),
signature: "bypass"
})
});
return paymentInfo;
}
function preparePayments() {
Balancy.Actions.Ads.setAdWatchCallback((storeItem : SmartObjectsStoreItem) => {
console.log('Fake ad watched for:', storeItem?.name);
//TODO Implement your ad watch logic here
storeItem?.adWasWatched();
});
Balancy.Actions.Purchasing.setHardPurchaseCallback((productInfo) => {
console.log('Starting Purchase: ', productInfo?.productId);
const price = productInfo?.getStoreItem()?.price;
// Implement your hard purchase logic here
if (price) {
const paymentInfo = createTestPaymentInfo(price);
//Tell Balancy that payment was successful
Balancy.API.finalizedHardPurchase(true, productInfo, paymentInfo);
} else {
console.warn('No price information available for the product:', productInfo?.productId);
Balancy.API.finalizedHardPurchase(false, productInfo, null);
}
});
Balancy.Actions.Purchasing.setGetHardPurchaseInfoCallback((productId) => {
const allStoreItems = Balancy.CMS.getModels(SmartObjectsStoreItem, true);
let price = 0.01;
for (const storeItem of allStoreItems) {
if (storeItem?.price?.product?.productId === productId) {
price = storeItem.price.product.price;
break;
}
}
return new BalancyHardProductInfo(
"Test Purchase",
"Test Purchase Description",
`$${Number(price).toFixed(2)}`,
price,
"USD");
});
}
Payment Callbacks Explained:¶
setAdWatchCallback- Called when a user wants to watch an adsetHardPurchaseCallback- Called when a user initiates a real money purchasesetGetHardPurchaseInfoCallback- Used by Balancy UI to get product information (pricing, descriptions)
For more details about the payment system, see the Payments Guide.
Demo¶
Clone a complete working example from our public GitHub project: Balancy TypeScript Example.
You can also access the Live Demo.
Next Steps¶
To learn more about Balancy methods and callbacks:
- Initialization Guide - Detailed initialization options
- Advanced Setup - Code Generation, advanced setup and configuration
- API Reference - Complete API documentation