tpocket (token pocket) is an out-of-the-box in-memory backpack implementation of the ft/nft model for tokenlization. It is based on the memstore protocol, so projects that use tpocket can also easily implement it externally for persistence
tpocket is a useful tool for developers who want an easy way to implement tokenization in their projects. Its in-memory backpack implementation makes it fast and efficient, and its use of the memstore protocol makes it easy to implement for persistence. This means that developers can use tpocket without having to worry about complicated setup or maintenance.
A fungible token (FT) is a token that can be easily replaced.
tpocket can be used to implement a fungible token system for in-game currency. For example, tpocket can be used to manage resources such as gold, experience points, and energy.
usage
package main
import (
"context"
"fmt"
"github.com/khgame/memstore"
"github.com/khgame/tpocket"
)
var (
weaponPocket tpocket.FTPocket
)
// SetWeapon - set weapon to user
func SetWeapon(ctx context.Context, user string, weaponPresetId int64, count int64) error {
ft := tpocket.SealFT(weaponPresetId)
ft.Quantity = count // set quantity to 100
if err := weaponPocket.Set(ctx, user, ft); err != nil {
return err
}
return nil
}
// initialize pocket
func main() {
// init pocket
app := "game1"
pocketName := "user_weapon"
persistKey := fmt.Sprintf("%s:%s", app, pocketName)
// create a storage
storage := memstore.NewInMemoryStorage[tpocket.FT](persistKey)
pocket = tpocket.MakeFTPocket(context.Background(), app, pocketName, storage)
}A non-fungible token (NFT) is a unique token that cannot be replaced or exchanged for another token. tpocket can also be used to implement NFTs, which can be used for various purposes such as in-game items, collectibles, roles, and digital art. For example
- NFT can represent unique weapons or equipment in games that only certain players can use. These NFTs can be traded or sold between players, creating a player-driven economy.
- NFT can represent unique items or characters in games. These NFTs can be gifted, purchased, or earned, and can be traded or sold between players.
- NFT can represent unique maps or scenes in games. These NFTs can be purchased or earned, and players can use them to create their own game content, or trade and sell them.
- NFT can represent unique tasks or challenges in games. These NFTs can be purchased or earned, and players can complete tasks or challenges to obtain them, or trade and sell them.
The use cases for NFTs are almost limitless, and tpocket provides developers with a simple and efficient way to implement NFTs in their projects.