CocosCreator with Telegram Game (Part 2) - TON Payment

Learning how to use CocosCreator to develop Telegram game and use the TON payment

CocosCreator Development of Telegram Games (Part Two) - TON Payment

In this article, we will continue to explore how to develop Telegram games using CocosCreator, focusing on how to integrate TON payment functionality. Through this tutorial, you will learn how to connect to TON Connect in your game, implement wallet connection, payment, and the verification after pay, and then providing decentralized payment for your game. Next, we will introduce how to implement TON payment integration step by step. We hope this tutorial will be helpful to you.

CocosCreator + Telegram

If you don't know much about CocosCreator and Telegram, you can read previous blog first.

Integrate TON Connect into your game

1. Add tonconnect-ui.min.js to the index.html

<script src="https://unpkg.com/@tonconnect/ui@latest/dist/tonconnect-ui.min.js"></script>

2. Add a div to use the wallet

<!-- Add this div into HTML -->
<div id="ton-connect"></div>

3. Initialize TonconnectUI

// TonConnectUI
// @ts-ignore
this.tonConnectUI = new window.TON_CONNECT_UI.TonConnectUI(
{
  manifestUrl: 'https://xxxxxxxx/tonconnect-manifest.json',
  buttonRootId: 'ton-connect', // confirm this ID is the same as above div
  chain: 'testnet',
  network: 'testnet', // mainnet
});

// Redirect the user to the Telegram mini program after the wallet is connected
this.tonConnectUI.uiOptions = {
  twaReturnUrl: 'https://t.me/RainbowJourneyBot',
};
P1

4. Connect to wallet

P2
P3

5. Pay

6. Verify

After the payment is completed, you will get the boc, and take the boc to the backend for verification to obtain the in-game items.

P4

That's all, the centralized game connect to Telegram payment in ton has ended. I hope it will be helpful to you.

Last updated

Was this helpful?