TON blockchain bindings and utilities for cocos game engines
This project is forked from https://github.com/ton-org/game-engines-sdk
Installation:
npm install --save @cocos-labs/game-sdk
Creating GameFi instance:
// creation options described in the related section
import { CocosGameFi, TonConnectUI, Address, toNano } from '@cocos-labs/game-sdk';
// https://docs.ton.org/develop/dapps/ton-connect/manifest
let uiconnector = new TonConnectUI({
manifestUrl: '{YOU_PROJECT_MANIFESURL}'
});
const gameFi = await CocosGameFi.create({ connector: uiconnector });
GameFi static methods:
| Method | Description |
|---|---|
| create | creates a GameFi instance |
GameFi instance methods:
| Method | Description |
|---|---|
| connectWallet | connect wallet manually (without build-in UIs) |
| onWalletChange | watch weather wallet was connected or disconnected |
| disconnectWallet | disconnect wallet manually (without build-in UIs) |
| buyWithTon | buy from in-game shop with TON |
| buyWithJetton | buy from in-game shop with jetton |
| transferTon | transfer TON to another wallet address |
| transferJetton | transfer jetton to another wallet address |
| openNftCollection | open NFT collection contract |
| openNftSale | open NFT collection contract |
| openNftItem | open NFT item contract |
| openNftItemByIndex | open NFT item contract using its index |
| openSbtCollection | open SBT collection contract |
| openJetton | Open Jetton contract |
| openJettonWallet | Open Jetton Wallet contract |
GameFi instance props:
| Prop | Description |
|---|---|
| assetsSdk | asset-sdk instance in case you need to use it directly |
| walletConnector | wallet connector instance in case you need to use it directly |
| wallet | user's connected wallet |
| walletAccount | user's connected account |
| walletAddress | user's connected wallet address |
| merchantAddress | in-game shop's address to receive TON |
| merchantJettonAddress | in-game shop's jetton used as in-game currency |
To learn complex use cases read TON GameFi article and check out the source code of demo Flappy Bird game.
The full typedoc references.