LearnCard Documentation
GithubStatusSupportLaunch App
  • 🚀Introduction
    • What is LearnCard?
    • Use Cases & Possibilities
    • Ecosystem Architecture
  • ⚡Quick Start
    • Setup & Prerequisites
    • Your First Integration
  • 📚Tutorials
    • Create a Credential
    • Create a Boost
    • Create a ConsentFlow
    • Create a Connected Website
    • Send xAPI Statements
    • Listen to Webhooks
  • ✅How-To Guides
    • Verify My Issuer
    • Connect Systems
      • Connect a Website
      • Connect a Game
    • Implement Flows
      • Claim Data after Guardian Consent
      • Connect via CHAPI
        • ⭐CHAPI Wallet Setup Guide
        • ↔️Translating to CHAPI documentation
        • 🖥️Demo Application
        • 🔰Using LearnCard to Interact with a CHAPI Wallet
        • 📝Cheat Sheets
          • Issuers
          • Wallets
    • Deploy Infrastructure
      • Remote Key Management
      • Generate API Tokens
      • Signing Authority
      • Connect to Independent Network
      • Build a Plugin
  • 🛠️SDKs & API Reference
    • LearnCard Wallet SDK
      • Authentication
      • Usage Examples
      • SDK Reference
      • Plugin API Reference
      • Integration Strategies
      • Deployment
      • Troubleshooting
      • Changelog
    • LearnCloud Network API
      • Authentication
      • Usage Examples
      • Architecture
      • Notifications & Webhooks
      • Profiles
      • Profile Managers
      • Credentials
      • Boosts
      • Presentations
      • Storage
      • Contracts
      • DID Metadata
      • Claim Hooks
      • Auth Grants
      • Utilities
      • Models
      • OpenAPI
    • LearnCloud Storage API
      • Authentication
      • Usage Examples
      • Architecture
      • Storage
      • Index
      • User
      • Custom Storage
      • Utilities
      • Models
      • xAPI Reference
    • Plugins
      • Crypto
      • DIDKit
      • DID Key
      • Dynamic Loader
      • VC
        • Expiration Sub-Plugin
      • VC-Templates
      • VC-API
      • Ceramic
      • IDX
      • VPQR
      • Ethereum
      • CHAPI
      • LearnCard Network
      • LearnCloud
      • LearnCard
      • Simple Signing
      • Claimable Boosts
    • LearnCard CLI
  • 🧠Core Concepts
    • Identities & Keys
      • Decentralized Identifiers (DIDs)
      • Seed Phrases
      • Network Profiles
      • Signing Authorities
      • Trust Registries
    • Credentials & Data
      • Verifiable Credentials (VCs)
      • Credential Lifecycle
      • Schemas, Types, & Categories
      • Building Verifiable Credentials
      • Boost Credentials
      • Getting Started with Boosts
      • Credential URIs
      • xAPI Data
      • General Best Practices & Troubleshooting
    • Consent & Permissions
      • ConsentFlow Overview
      • Consent Contracts
      • User Consent & Terms
      • Consent Transactions
      • Auto-Boosts
      • Writing Consented Data
      • Accessing Consented Data
      • GameFlow Overview
    • Network & Interactions
      • Network Vision & Principles
      • Key Network Procedures
      • Core Interaction Workflows
    • Architecture & Principles
      • Control Planes
      • Plugin System
      • Auth Grants and API Tokens
  • 🔗Development
    • Contributing
Powered by GitBook
On this page
  • Quick Start
  • Boilerplate
  • Install @learncard/core
  • Create the Types
  • Create the Plugin
  • Create a Test for Your Plugin
  • Publish Your Plugin to NPM
  • Make an npm account
  • Create the package boilerplate
  • Create a Github Repo
  • Release the Package
  • Next Steps

Was this helpful?

  1. How-To Guides
  2. Deploy Infrastructure

Build a Plugin

The simplest plugin

PreviousConnect to Independent NetworkNextLearnCard Wallet SDK

Last updated 3 days ago

Was this helpful?

Quick Start

Boilerplate

Start with a basic TypeScript node package boilerplate. If you've never done that before, we recommend using :

If you don't have aqu installed, you can install it globally with npm i -g aqu.

pnpm dlx aqu create simple-plugin

? Pick package manager: pnpm
? Specify package description: ()
? Package author:
? Git repository (only for package.json information):
? Pick license: MIT
? Pick template: typescript

cd simple-plugin
yarn dlx aqu create simple-plugin

? Pick package manager: yarn
? Specify package description: ()
? Package author:
? Git repository (only for package.json information):
? Pick license: MIT
? Pick template: typescript

cd simple-plugin
npx aqu create simple-plugin

? Pick package manager: npm
? Specify package description: ()
? Package author:
? Git repository (only for package.json information):
? Pick license: MIT
? Pick template: typescript

cd simple-plugin

If you'd like to publish your plugin to npm for others to use, please see our documentation on

Install @learncard/core

Using your preferred package manager, install @learncard/core

pnpm i @learncard/core
yarn add @learncard/core
npm i @learncard/core

Create the Types

src/types.ts
import { Plugin } from '@learncard/core';

export type MyPluginMethods = {
    getFavoriteNumber: () => number;
};

export type MyPluginType = Plugin<'MyPluginName', any, MyPluginMethods>;

The preceding file defines a plugin named MyPluginName that exposes one method: getFavoriteNumber

Create the Plugin

src/index.ts
import { MyPluginType } from './types';

export const MyPlugin: MyPluginType = {
    name: 'MyPluginName',
    methods: { getFavoriteNumber: () => 4 },
};

Create a Test for Your Plugin

pnpm i --save-dev jest @types/jest
yarn add jest @types/jest --dev
npm i --save-dev jest @types/jest

Then, write your test:

test/index.test.ts
import { initLearnCard } from '@learncard/core';
import { MyPlugin } from '../src/index';

describe('MyPlugin', () => {
	it('should return my favorite number', async () => {
		const learnCard = await initLearnCard();
		const learnCardWithMyPlugin = await learnCard.addPlugin(MyPlugin);

		const favoriteNumber = learnCardWithMyPlugin.invoke.getFavoriteNumber();
		
		expect(favoriteNumber).toBe(4);
	});
});

If all looks good, you should be able to pnpm test and successfully pass the test:

That's it—you've got a simple plugin! 🎉

Now you can add it to a LearnCard object:

const learnCard = await initLearnCard();
const learnCardWithMyPlugin = await learnCard.addPlugin(MyPlugin);

console.log(learnCard.invoke.getFavoriteNumber()); // 4

Publish Your Plugin to NPM

If you don't have anything secret contained in your plugin, you are encouraged to publish it as a package to NPM and share it with the world 🏆.

Let's walk through how to do that together:

Make an npm account

Create the package boilerplate

yarn dlx aqu create learn-card-example-plugin

? Pick package manager: yarn
? Specify package description: () # Describe your plugin!
? Package author: # Who are you?
? Git repository (only for package.json information): 
? Pick license: MIT # See https://choosealicense.com/
? Pick template: typescript

cd learn-card-example-plugin
pnpm dlx aqu create learn-card-example-plugin

? Pick package manager: pnpm
? Specify package description: () # Describe your plugin!
? Package author: # Who are you?
? Git repository (only for package.json information): 
? Pick license: MIT # See https://choosealicense.com/
? Pick template: typescript

cd learn-card-example-plugin
npx aqu create learn-card-example-plugin

? Pick package manager: npm
? Specify package description: () # Describe your plugin!
? Package author: # Who are you?
? Git repository (only for package.json information): 
? Pick license: MIT # See https://choosealicense.com/
? Pick template: typescript

cd learn-card-example-plugin

Create a Github Repo

gh auth login

After getting all setup, initialize and create the repo with the following commands:

git init

echo "node_modules/" >> .gitignore
echo "dist/" >> .gitignore

git add .
git commit -m "Initial Commit"

gh repo create
? What would you like to do? Push an existing local repository to GitHub
? Path to local repository .
? Repository name learn-card-example-plugin
? Description Example LearnCard Plugin!
? Visibility Public
✓ Created repository {REPOSITORY_NAME} on GitHub
? Add a remote? Yes
? What should the new remote be called? origin
✓ Added remote {REPOSITORY_URL}
? Would you like to push commits from the current branch to "origin"? Yes
✓ Pushed commits to {REPOSITORY_URL}

After getting a repo up, it's a good idea to add the URL (shown above as {REPOSITORY_URL}) to the package.json!

package.json
  "repository": {
    "type": "git",
    "url": {REPOSITORY_URL}
  },

Release the Package

With everything set up, you may run the release command!

pnpm release
yarn release
npm run release

If you didn't use aqu to create your package, you may need to use the publish command directly:

pnpm publish
yarn publish
npm publish

Congratulations! 🥳 Your plugin is officially published and others may use it by installing it from npm!

Next Steps

For more info on adding plugins to a LearnCard:

For more info on constructing the LearnCard object:

To ease plugin development, it's best to start by defining the interface for your plugin. This can be done quite easily using :

It's important to write tests for your plugins, so others can rely on them

If you haven't yet, . You will need to come up with a username, email, and password!

As noted in our docs on , if you've never set up a TS/node package before, we greatly recommend using !

If you've selected an open source license (such as MIT or ISC), please make a Github Repo containing the code to your plugin! If you've never done this before, we recommend using the .

First, create a , then install and login with the CLI. This is usually done with the following command:

✅
👍
follow these short steps to create an npm account
Github CLI
Github Account
Plugin System
Usage Examples
aqu
publishing plugins
aqu
The Simplest Plugin
the Plugin type