Claimable Boosts
@learncard/claimable-boosts-plugi
This plugin for LearnCard enables the creation of "Claimable Boosts," which are credentials that users can claim via a unique link or QR code. It allows external partners or systems to easily generate and distribute credentials (boosts) without needing direct interaction with the end-user's wallet initially.
Installation
Choose your preferred package manager:
# Using npm
npm install @learncard/init @learncard/claimable-boosts-plugin @learncard/lca-api-plugin
# Using yarn
yarn add @learncard/init @learncard/claimable-boosts-plugin @learncard/lca-api-plugin
# Using Bun
bun add @learncard/init @learncard/claimable-boosts-plugin @learncard/lca-api-pluginQuickstart
This example shows the minimum setup to generate your first claimable boost link.
Prerequisites:
Node.js (v14 or later) installed.
A secure seed phrase for initializing LearnCard. Never hardcode your seed in production code. Use environment variables or a secure secrets management system. For this example, we'll use an environment variable
SECURE_SEED.A unique ID for your issuer profile (e.g.,
my-awesome-org-profile).
Steps:
Create a script (e.g.,
createBoost.js):
Run the script:
Set the environment variable:
Execute the script:
Output: The script will print the generated claim link to your console. Anyone with this link can claim the "Quickstart Achievement" boost.
Next Steps: Explore the "Detailed Usage" section below for customizing claim links (e.g., setting expiry times, usage limits), generating QR codes, and understanding the process in more detail.
Detailed Usage
This section provides a comprehensive walkthrough of creating and managing Claimable Boosts.
Prerequisites:
Node.js (v14 or later)
npm, yarn, or Bun
A LearnCard Network account (implied by using the plugin with
network: true)A secure seed phrase for your issuer identity.
Setup Process
Import Required Plugins:
Initialize LearnCard: Instantiate LearnCard, enabling network features and adding necessary plugins. The seed should be kept secure and never exposed in client-side code or committed to repositories.
Creating Claimable Boosts Flow
Create an Issuer Profile (One-time Setup per Profile ID): Define your organization's identity on the network. The profileId must be unique.
Note: Your initialized learnCard instance (via its seed) becomes the controller/owner of this profile ID.
Create a Boost Template: Define the structure and content of the credential (boost) you want to issue. This follows the W3C Verifiable Credential data model, often using specific LearnCard contexts.
Note: The newCredential method helps structure the credential but doesn't sign or issue it yet. The issuer field will typically be derived from your learnCard instance's DID. The credentialSubject.id is intentionally omitted; it will be assigned to the claimant upon claiming. More info on creating verifiable credentials for LearnCard here.
Create the Boost: Register the boost template on the LearnCard Network, making it potentially claimable. This associates the template with your profile.
The returned boostUri is a unique identifier for this specific registered boost on the network.
Generate Claim Links: Create a unique URL that users can visit to claim their instance of the boost.
Claim Link Options
You can customize the behavior of claim links by providing an options object:
Available Options:
ttlSeconds
Integer
Number of seconds until the link expires.
null (no expiry)
totalUses
Integer
Maximum number of times the link can be successfully claimed.
null (unlimited)
Use Cases for Options:
Limited-time offers: Set
ttlSecondsfor time-sensitive campaigns or events.Limited quantity: Set
totalUsesfor exclusive rewards or limited-enrollment programs.Unique links per user: Set
totalUses: 1. You would generate a unique link for each intended recipient.
QR Code Generation
Easily generate data suitable for QR code generation, which encodes the claim link.
Common Issues & Troubleshooting
"Profile ID already exists": This error occurs during
createProfileif the profileId is already registered on the network. You can either choose a different unique profileId or safely ignore this error if you intend to use the existing profile (as shown in the Quickstart and Setup examples). Ensure the learnCard instance you're using is the controller of the existing profile if you intend to manage it."Invalid credential format": Double-check that your boostTemplate conforms to the expected structure. Refer to LearnCard documentation for specific schema requirements.
"Network error" / "Failed to fetch": Verify your internet connection. Ensure the LearnCard API endpoint (https://api.learncard.app/trpc by default) is accessible. Check for any network proxies or firewalls that might be blocking the connection.
"Authentication Error" / "Unauthorized": Ensure your seed is correct and corresponds to the DID that controls the profileId you are trying to manage (especially when creating boosts under an existing profile).
Seed Security: Remember to handle your seed phrase securely using environment variables or a dedicated secrets manager. Avoid hardcoding it directly in your source code.
Complete Example Script
This script combines all steps, including basic error handling for profile creation.
License
MIT © Learning Economy Foundation
Last updated
Was this helpful?