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.
Our Project: Pixel Pet Designer
We'll create a fun, simple app where users can:
Design a pixel art pet on a 10x10 grid.
Name their pet.
"Submit" their design. Upon submission, our app will:
Prompt the user (and their guardian, if applicable) to connect their LearnCard account via GameFlow.
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.htmlstyle.cssapp.jsserver.js(We'll work on this later for the backend)
Step 1.2: index.html - The Basic Structure
index.html - The Basic StructureStep 1.3: style.css - Basic Styling
style.css - Basic StylingStep 1.4: app.js - Basic Frontend Logic (Pixel Grid)
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)
server.js)Create server.js:
Action
Replace
YOUR_PIXELPET_GAME_SECURE_64_CHAR_HEX_SEEDwith a unique 64-character hex string.Start your backend:
node server.js(ornpx ts-node server.jsif using TypeScript).
Part 3: Connecting LearnCard - Frontend
Now, let's make the "Connect with LearnCard" button functional.
Step 3.1: Update app.js to Fetch Consent URL
app.js to Fetch Consent URLAction
Test this. Open index.html. Your backend server (server.js) should be running. Clicking the "Connect with LearnCard" button should now redirect you to learncard.app. You'll see your GameFlow contract details. Since needsGuardianConsent: true, you'll be guided through the guardian consent flow.
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
server.jsStep 4.2: Frontend - Handle Successful Connection (app.js)
app.js)Update app.js to check for the learncard_did from the redirect and update the UI.
Action
Restart your
server.js.Go through the "Connect LearnCard" flow from your
index.html.Complete the consent (and guardian steps if prompted) on
learncard.app.You should be redirected back to
index.html(or your specified callback, then to index.html), and the UI should update to show the connected DID. The "Create & Get Badge!" button should now be enabled.
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
app.js for Pet SubmissionPart 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).
Step 6.2: Backend - Create the /api/issue-pet-badge Endpoint
/api/issue-pet-badge EndpointAdd this new route to your server.js.
Action
Add the
getOrCreatePixelPetBoostfunction and call it during server startup.Add the
/api/issue-pet-badgeendpoint to yourserver.js.Restart your
server.js.Go back to your
index.htmlin the browser.Connect LearnCard (if not already).
Design your pixel pet, give it a name.
Click "Create & Get Badge!"
You should see logs on both your frontend and backend. The frontend will update to show the badge was issued, and if you check the LearnCard app associated with the playerLearnCardDid, you should find your new "Pixel Pet: [YourPetName]" badge!
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
evidencefield.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?