Create a Connected Website

Tutorial: Build 'Pixel Pet Designer' & Connect with LearnCard GameFlow

Welcome, game developer! This tutorial is a practical, step-by-step lesson where you'll build a simple web application called "Pixel Pet Designer." More importantly, you'll learn how to integrate it with LearnCard using GameFlow to issue unique, verifiable digital badges to your users for their creations, complete with guardian consent for younger players.

What is GameFlow? GameFlow is LearnCard's specialized framework for educational games. It allows your game to securely interact with a player's LearnCard digital wallet to issue achievement badges and, optionally, track learning progress. A key feature is its built-in guardian consent system, ensuring a safe experience for younger learners. (For a deeper dive, see our GameFlow Core Concept.)

Our Project: Pixel Pet Designer

We'll create a fun, simple app where users can:

  1. Design a pixel art pet on a 10x10 grid.

  2. Name their pet.

  3. "Submit" their design. Upon submission, our app will:

  4. Prompt the user (and their guardian, if applicable) to connect their LearnCard account via GameFlow.

  5. Issue a verifiable digital badge (a "Pixel Pet Creation" badge) containing the pet's name and its design data.

This tutorial focuses on the learning experience of integrating LearnCard. We'll keep the game logic itself very simple to concentrate on the GameFlow integration.

What you'll learn by doing:

  • How to set up your web application's backend as a LearnCard Issuer.

  • How to define and create a GameFlow Contract, including needsGuardianConsent.

  • How to implement a "Connect with LearnCard" button on your website.

  • How your backend can handle the LearnCard callback, capturing the player's DID after consent (including the guardian flow).

  • How to issue a Verifiable Credential (badge) with custom data (the pet's name and design) from your application.

Prerequisites:

  • Node.js (v16+ recommended): For running a simple backend server.

  • Basic HTML, CSS, and JavaScript knowledge: We'll build a simple frontend.

  • Text Editor: Your favorite code editor (e.g., VS Code).

  • LearnCard SDK Packages: You'll install these in your project.

  • A Secure Seed for your Issuer: A 64-character hexadecimal string. For this tutorial, generate one for testing; for production, it must be cryptographically random and kept highly secure.

  • Familiarity (Recommended): Briefly review DIDs, Verifiable Credentials (VCs), and the general ConsentFlow Tutorial.

Let's get started!

Part 1: Setting Up the "Pixel Pet Designer" Frontend

First, let's create the basic visual part of our application.

Step 1.1: Project Setup

Create a new folder for your project, e.g., pixel-pet-designer. Inside it, create the following files:

  • index.html

  • style.css

  • app.js

  • server.js (We'll work on this later for the backend)

Step 1.2: index.html - The Basic Structure

Step 1.3: style.css - Basic Styling

Step 1.4: app.js - Basic Frontend Logic (Pixel Grid)

At this point, you should be able to open index.html in your browser and see the Pixel Pet Designer interface. You can draw, but submitting doesn't do anything related to LearnCard yet.

Part 2: Setting Up the Backend (Issuer & GameFlow Contract)

Your game's backend will handle LearnCard initialization, contract creation, and credential issuance. We'll use Node.js with conceptual Express-like routing for this tutorial.

Step 2.1: Install Dependencies

In your project folder (pixel-pet-designer), open your terminal:

Step 2.2: Backend Setup (server.js)

Create server.js:

Action

Part 3: Connecting LearnCard - Frontend

Now, let's make the "Connect with LearnCard" button functional.

Action

Part 4: Connecting LearnCard - Backend Callback

After the user (and guardian, if applicable) consents on learncard.app, they are redirected back to YOUR_GAME_CALLBACK_URL (http://localhost:3000/learncard-callback).

Step 4.1: Implement the Callback Endpoint in server.js

Step 4.2: Frontend - Handle Successful Connection (app.js)

Update app.js to check for the learncard_did from the redirect and update the UI.

Action

Part 5: Designing & Submitting a Pet (Frontend)

This part focuses on capturing the pet design and name.

Step 5.1: Update app.js for Pet Submission

Part 6: Issuing the Pet Badge (Backend)

When the frontend submits the pet data, your backend issues the Verifiable Credential.

Step 6.1: Create a Boost for "Pixel Pet Creation" Badges (One-time Setup)

Add this to your server.js (or a separate badge-manager.js like in the previous tutorial).

Action

Step 6.2: Backend - Create the /api/issue-pet-badge Endpoint

Add this new route to your server.js.

Action

Summary & Next Steps

Congratulations! You've successfully built "Pixel Pet Designer" and integrated it with LearnCard GameFlow to: βœ… Set up your game as a LearnCard Issuer. βœ… Create a GameFlow Contract enabling guardian consent. βœ… Allow players/guardians to connect their LearnCard accounts. βœ… Handle the consent callback and link player DIDs. βœ… Automatically issue a custom "Pixel Pet Creation" badge when a pet is designed.

This tutorial demonstrates a powerful way to add verifiable achievements and data portability to your educational games.

From here, you can explore:

  • Storing Pet Designs: Instead of just embedding pixel data in the VC, you could save the design (e.g., as an image or JSON on a server) and include a URL to it in the VC's evidence field.

  • xAPI Integration: Use the delegateVpJwt (captured in Part 4) to send xAPI statements about game activities (e.g., "Player X started designing a pet," "Player X submitted pet Y").

  • Advanced Boost Features: Explore Boost permissions, hierarchies, and more detailed display customizations.

  • Error Handling & UI/UX: Improve the user interface, error messages, and overall flow for a production-ready game.

You're now equipped to bring the power of Verifiable Credentials and LearnCard GameFlow to your own educational projects!

Last updated

Was this helpful?