Openable Card Pack
Creating and opening a card pack using HandCash Items
This example demonstrates how to create an unopened card pack with an “Open” action, and then process the opening of the pack when a user activates the action.
Step 1: Create Unopened Card Pack
First, create an unopened card pack item with an “Open” action:
Step 2: Handle Pack Opening
When a user activates the “Open Pack” action, they will be redirected to your game’s API endpoint with their auth token and the item’s origin. Your server should then process the pack opening using the provided auth token:
Process Overview
- Create Card Pack: Your game creates an unopened card pack item with an “Open Pack” action.
- User Interaction: The user purchases the pack from the HandCash market and selects the “Open Pack” action.
- Redirect: HandCash redirects the user to your game’s API with the user’s auth token and the pack’s item origin.
- Authentication: Your server creates a new HandCashMinter instance using the auth token provided in the query parameters.
- Generate Cards: Your game logic generates random cards to represent the pack’s contents.
- Burn and Create: In a single API call, your server burns the unopened pack and creates the new card items using the authenticated HandCashMinter instance.
- User Feedback: The user is redirected to a page showing their newly opened cards.
This example demonstrates how to create interactive items that can transform into other items, providing an engaging experience for users while leveraging the HandCash Items API for secure and efficient item management. The key change is using the auth token from the query parameters to authenticate the action, ensuring that the operation is performed on behalf of the correct user.