Skip to content

Instantly share code, notes, and snippets.

View barinbritva's full-sized avatar
🏴‍☠️
Karibu!

barinbritva

🏴‍☠️
Karibu!
View GitHub Profile
@barinbritva
barinbritva / objectEntries.ts
Created March 13, 2023 12:24
typesafe objectEntries
// https://stackoverflow.com/a/74891854/3359277
export function typeSafeObjectEntries<
T extends { [key: string | number | symbol]: unknown },
K extends keyof T,
V extends T[K]
>(o: T) {
return Object.entries(o) as unknown as [K, V][];
}
@barinbritva
barinbritva / flappy-article.md
Last active November 8, 2024 16:46
flappy bird article

TON blockchain for games

What’s in the tutorial

In this tutorial we will consider how to add TON blockchain to a game. For our example we will use a Flappy Bird clone written in Phaser and will add GameFi features step by step. In the tutorial we will use short code pieces and pseudocode to make it more readable. Also, we will provide links to real code blocks to help you understand better. The whole implementation can be found in the demo repo.

Flappy Bird game without GameFi features

We are going to implement the following:

  • Achievements. Let’s reward our users with SBTs. Achievement system is a great tool to increase user engagement.
  • Game currency. In TON blockchain it’s easy to launch your own token (jetton). The token can be used to create an in-game economy. Our users will be able to earn the game coins to spend them later.

Lecture 1 - Setting up bot and mini app

Create a bot

  • Create a bot in @BotFather https://t.me/BotFather using /newbot command
  • Enter a bot name. Example: Water Balance
  • Enter a bot username. Example: WaterBalanceBot.
  • You get a link to your bot like t.me/WaterBalanceBot, use it to open bot later. You can also use bot handle @WaterBalanceBot to find it via search box

Add some prefix to a bot handle as far WaterBalance is already in use

Create a mini app