---
title: "Build your first plugin"
description: "Validate, sign, publish, and install the loyalty discount example plugin."
---

> Documentation Index
> Fetch the complete documentation index at: https://edgecart.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Build your first plugin

This tutorial uses the `loyalty` example in the EdgeCart repository. It is a
minimal sandboxed plugin that proposes an order discount based on a
merchant-configured percentage.

## Before you start

- Node.js 22+ and a checkout of the EdgeCart repository.
- The plugin kernel deployed (or running locally) and its endpoint URL.
- Access to **Plugin registry** in the EdgeCart admin.
- The merchant store where you will install the plugin.

## Steps

1. **Validate the manifest**

   ```sh
   node --experimental-strip-types packages/plugin-cli/bin/edgecart-plugin.mjs \
     validate examples/plugins/loyalty/manifest.json
   ```

   The command prints the plugin id, version, and trust hash.
2. **Generate a signing key**

   ```sh
   node --experimental-strip-types packages/plugin-cli/bin/edgecart-plugin.mjs \
     keygen --out loyalty-key.json
   ```

   The file contains a base64 Ed25519 public key and private key. Keep the
   private key local; it is written with `0600` permissions.
3. **Register a publisher**

   In **Admin → Plugin registry**, create a publisher and paste the public
   key. Create a publisher API key and copy it once; EdgeCart stores only its
   hash.

   Registry operations require the operator's email to be in
   `PLATFORM_ADMIN_EMAILS`.
4. **Publish the bundle**

   ```sh
   node --experimental-strip-types packages/plugin-cli/bin/edgecart-plugin.mjs \
     publish \
     examples/plugins/loyalty/manifest.json \
     examples/plugins/loyalty/backend.js \
     --endpoint https://edgecart-plugins.example.com \
     --api-key <publisher-api-key> \
     --private-key "$(jq -r .private_key loyalty-key.json)"
   ```

   The CLI signs the bundle and posts it to `/v1/releases`. The release starts
   in `pending` review.
5. **Approve the release**

   In **Admin → Plugin registry**, approve the pending release. Only approved,
   non-yanked releases can be installed.
6. **Install and configure**

   In **Admin → Plugins**, install **Loyalty Discount**. Review the trust hash
   and capabilities (`discounts:propose`, `settings`, `admin:ui`), accept the
   consent, and set the discount **percent** in the plugin settings.
7. **Verify**

   Add products to a cart. The plugin's `cart:calculate` hook proposes an
   order discount; the host validates it and recalculates the totals. The
   cart should show the discount without trusting a plugin-supplied total.

## What the example does

- The manifest declares the `cart:calculate` hook and a `percent` setting.
- The bundle exports a default `fetch` handler. It reads `invocation.config`
  and returns `{ ok: true, value: { adjustments: [...] } }`.
- The host checks the adjustment's target, currency, and amount bounds, then
  recomputes the cart totals.
- A malformed response is rejected and recorded in the invocation log.

> **Bundle constraints**
>
> A plugin is one self-contained JavaScript module, at most 10 MiB. The
> manifest and bundle are signed; the trust hash shown during install covers
> the capabilities, hosts, hooks, storage, routes, and UI declarations.

## Next

- [Plugin manifest reference](https://edgecart.dev/plugins/manifest)
- [Capabilities and hooks](https://edgecart.dev/plugins/capabilities-hooks)
- [PluginContext](https://edgecart.dev/plugins/context)
- [CLI and registry publishing](https://edgecart.dev/plugins/cli-registry)

Source: https://edgecart.dev/plugins/quickstart/index.mdx
