@ton/game-engines-sdk

game-engines-sdk

TON blockchain bindings and utilities for game engines:

Getting started

Installation:

# for Phaser
npm install --save @ton/phaser-sdk@beta

# for Cocos
npm install --save @ton/cocos-sdk@beta

# for Cocos
npm install --save @ton/vanilla-sdk@beta

Creating GameFi instance:

// creation options described in the related section
const gameFi = await GameFi.create()

Connecting wallet:

// create the UI scene
class UiScene extends Phaser.Scene {}
const uiScene = new UiScene();

// add the connect button to the scene
// all options described in the related section
const button: Container = gameFi.createConnectButton({
scene: uiScene
})

Watching wallet connection:

gameFi.onWalletChange((wallet: Wallet | null) => {
// do the logic depending weather wallet is null or not
})

This can be used for:

  • Watch the wallet state and reflect it on the game UI
  • Restore connection with previously connected user wallet after app reloads

What SDK should I use?

Engine specific features can be included to related SDKs. For example, phaser-sdk has build-it UI for connecting wallet. There is almost no differences between SDKs features right now.

Start with SDK of related engine if you use one. Use @ton/vanilla-sdk otherwise.

GameFi methods & props

GameFi static methods:

Method Description
create creates a GameFi instance

GameFi instance methods:

Method Description
createConnectButton creates a button to connect a wallet.
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

Use cases

To learn complex use cases:

References

The full typedoc references.

Generated using TypeDoc