Economy v2 is now Generally Available. For support and feedback, go to the PlayFab Forum.
How it works
The pattern uses three Economy v2 building blocks:- A virtual currency (or stackable item) that represents the container itself—for example, “Treasure Chest Token.”
- A Bundle priced at 1 of that currency, containing the items the container should grant.
- A purchase call where the player spends 1 token to buy the bundle, which automatically unpacks and grants the items.
Prerequisites
- A PlayFab developer account.
- A Title created in Game Manager.
- At least one published catalog item that you want the container to grant.
Step 1: Create a virtual currency for the container
Create a virtual currency that represents the container. Each unit of this currency acts as one unopened container.Game Manager
- Go to Economy > Catalog (V2) > Currency.
- Select New currency.
- Set the Title to a descriptive name, such as
Treasure Chest. - Set the FriendlyId to a short code, such as
tc. - Select Save and publish.
REST API
Call CreateDraftItem:Step 2: Create a bundle priced at one container token
Create a bundle that contains the items you want the container to grant. Price the bundle at exactly one unit of the container currency.Game Manager
- Go to Economy > Catalog (V2) > Bundles.
- Select New bundle.
- Set the Title to describe the container’s contents, such as
Treasure Chest Contents. - Under Items, add the items and quantities you want the container to grant—for example, 1 Legendary Sword and 100 Gold.
- Under Price, set the price to 1 of your container currency (Treasure Chest).
- Select Save and publish.
REST API
Call CreateDraftItem:When a player purchases this bundle, the bundle is automatically unpacked—the individual items go directly to the player’s inventory.
Step 3: Grant container tokens to players
Grant the container currency to players through any mechanism that fits your game design:- Gameplay rewards—Grant tokens after completing a level, quest, or achievement by using AddInventoryItems.
- Store purchases—Sell the container token in a Store for another virtual currency or real money.
- Battle pass / seasonal rewards—Include the token as a reward tier.
AddInventoryItems to grant three Treasure Chest tokens:
Step 4: Open the container
When the player wants to open a container, call PurchaseInventoryItems to buy the bundle with one container token:Multiple container types
Create multiple container types by repeating this pattern. For example:
Each container type has its own currency and bundle.
Using a Store for container purchases
Use a Store to override the container bundle’s price. By using a store, you can offer the same container at different prices in different contexts (for example, a discounted “open” cost during an event):StoreId when purchasing:
Limitations
This pattern works for containers with fixed, deterministic contents. If you need randomized loot (where the contents vary each time a container is opened, similar to V1 containers paired with drop tables), see the Drop tables and randomized loot tutorial. This tutorial uses Azure Functions to:- Subtract the container token from the player’s inventory.
- Run your weighted random selection logic.
- Grant the resulting items through the inventory APIs.
