This is a quick start guide, for the detailed information, please refer and
Table of Contents
Overview
The TMA (Telegram Mini App) SDK allows you to integrate advertising functionality into your Telegram Mini App. This guide covers implementation across three different frameworks:
import { useEffect } from 'react';
function TMASDKProvider({ children }) {
useEffect(() => {
if (TE && typeof TE.onLoad === 'function') {
TE.onLoad()
} else {
console.error('onLoad is not a function');
}
}, []);
return <>{children}</>;
}
2. Offer Wall Button Component
const OfferWallButton = () => {
return (
<button
onClick={() => {
if (TE && typeof TE.offerWall === 'function') {
TE.offerWall();
} else {
console.error('TE is not defined or offerWall is not a function');
}
}}
>
Open Offer Wall
</button>
);
};
Next.js Implementation
1. Create BecScript Component
Create a new file components/BecScript.tsx:
'use client';
import Script from "next/script";
declare const TE: any;
export default function BecScript() {
return (
<Script
src="https://bec.apps-network.net/latest/bec.js?walletAddress=YOUR_WALLET_ADDRESS"
strategy="afterInteractive"
onLoad={() => {
if (typeof TE.onLoad === "function") {
TE.onLoad();
} else {
console.error('TE.onLoad is not a function');
}
}}
/>
);
}