LearnCard Developer Docs
  • πŸš€Get Started
    • πŸ‘‹Welcome
    • ⭐Who are you?
      • Learners & Employees
      • Traditional Educator
      • Non-Traditional Educator
      • Assessment Provider
      • Employer
      • App Developer & EdTech
      • DAO & Communities
      • Content Creators
      • Research Institutions
      • NGOs & Governments
      • Plugfest Partner
        • Guide for Interop Issuers
          • 🀽Creating an Interop Issuer
        • Guide for Interop Wallets
    • Protocol Overview
      • The Internet of Education
      • The Learning Economy
      • Learner & Employee Privacy
      • 22nd Century Education
      • The Open Credential Network
      • PVCs
  • πŸ”°LearnCard SDK
    • What is LearnCard?
      • Why a Universal Wallet?
      • Architectural Patterns
      • Production Deployment Guide
      • Troubleshooting Guide
    • LearnCard Core
      • Quick Start
        • Create New Credentials
          • Creating Verifiable Credentials for LearnCard
          • Achievement Types and Categories
          • Custom Types
          • Understanding Boosts
          • Creating Boost Credentials
        • Sign & Send Credentials
        • Accept & Verify Credentials
        • Share & Present Credentials
      • Construction
        • Managing Seed Phrases
        • initLearnCard
        • DIDKit
        • learnCardFromSeed
        • emptyLearnCard
        • IDX Config
      • Control Planes
        • ID
        • Read
        • Store
        • Index
        • Cache
        • Context
      • Plugins
        • Adding Plugins
        • Official Plugins
          • Dynamic Loader
          • Crypto
          • DIDKit
          • DID Key
          • VC
            • Expiration Sub-Plugin
          • VC Resolution
          • VC-Templates
          • VC-API
          • Ceramic
          • IDX
          • VPQR
          • Ethereum
          • CHAPI
          • LearnCard Network
          • LearnCloud
          • LearnCard
          • Claimable Boosts
        • Writing Plugins
          • The Simplest Plugin
          • The Plugin Type
          • The LearnCard Type
          • Implementing Control Planes
          • Implementing Methods
          • The Implicit LearnCard
          • Depending on Plugins
          • Private Fields
          • Publishing a Plugin to NPM
      • URIs
      • CHAPI
        • ⭐CHAPI Wallet Setup Guide
        • ↔️Translating to CHAPI documentation
        • πŸ–₯️Demo Application
        • πŸ”°Using LearnCard to Interact with a CHAPI Wallet
        • πŸ“Cheat Sheets
          • Issuers
          • Wallets
      • LearnCard UX
        • Quick Start
        • Components
          • Verifiable Credentials
            • VC Thumbnail
            • VC Thumbnail, Mini
          • LearnCards
            • LearnCard Front
            • LearnCard Back
        • API
      • LearnCard Bridge
      • API
      • Migration Guide
    • LearnCard Network
      • LearnCard Network API
        • Authentication
        • Auth Grants and API Tokens
        • Profile
        • Credentials
        • Boosts
        • Presentations
        • Storage
        • Signing Authorities
        • Notifications
        • API Docs
        • Launch Your Own Network
      • πŸ”ŒConnect Your Application
    • ConsentFlow
      • Setting Up ConsentFlow with an Independent Network
    • GameFlow
      • Sending xAPI Statements
        • xAPI URIs
      • Reading xAPI Statements
        • Advanced xAPI Statement Queries
      • Consentful "Claim Later" Flow
  • πŸš€Applications
    • LearnCard
    • SuperSkills!
      • SuperSkills! SDK
        • Digital Wallets
        • Issuing into SuperSkills!
        • 🦸Creating a SuperSkills! Issuer
    • Metaversity
    • Admin Dashboard
  • πŸ”—Resources
    • Github
    • Community
    • πŸ’…Custom Development
    • Contact Our Team
    • Learning Economy
  • πŸ€–LearnCard Services
    • LearnCard CLI
    • Discord Bot
    • Metamask Snap
  • πŸ’ΈLearnBank SDK
    • Why LearnBank?
  • πŸ“ŠLearnGraph SDK
    • Why LearnGraph?
Powered by GitBook
On this page
  • Quick Start
  • Boilerplate
  • Install @learncard/core
  • Create the Types
  • Create the Plugin
  • Create a Test for Your Plugin

Was this helpful?

  1. LearnCard SDK
  2. LearnCard Core
  3. Plugins
  4. Writing Plugins

The Simplest Plugin

PreviousWriting PluginsNextThe Plugin Type

Last updated 2 years 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

For more info on adding plugins to a LearnCard:

For more info on constructing the LearnCard object:

To see how to publish this plugin to NPM for others to use:

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

πŸ”°
πŸ‘
aqu
publishing plugins
the Plugin type
Adding Plugins
Construction
Publishing a Plugin to NPM