my-game-engines-sdk
v0.0.2
Published
TON blockchain bindings and utilities for game engines: * [Phaser](https://phaser.io) * [Cocos](https://www.cocos.com/en) * Vanilla JavaScript
Downloads
8
Readme
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@betaCreating 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:
- read TON blockchain for games article
- check out the source code of Flappy Bird demo for Phaser
- check out the example of Flappy Bird for Cocos
References
The full typedoc references.
