An example project for building an NFP's front-end UI (the SVG file and application script).
NFP front-end development is divided into two subdirectories: the bootloader, and the app. Each one has its own build process, but they share configs in the root directory(package.json, tsconfig.json, .eslintrc.js, etc.).
For maximum portability, robustness, and longevity, a bootloader is a tiny minified script that fetches the NFP's latest packages from the chain and hydrates the running SVG document (e.g., by injecting scripts). The bootloader ensures that the raw, original SVG file can forever be opened and run as a standalone web application in any modern browser.
The @nfps.dev/runtime package provides a function that can be called by the project's bootloader to automatically handle resolving the NFP's dependencies by reading the requisite children of the <metadata> element. This approach allows project's to add some custom UI or logic to their bootloader flow.
NOTICE: NFP SVGs are immutable. Once an SVG is stored on chain, its bootloader cannot be modified.
Unlike the bootloader, a project's main application can be updated by deploying new package versions to the chain. The 'app' consists of any such packages, although most projects will only ever need to use a single main.js entrypoint script produced by a bundler (e.g., one produced by Vite).
The SVG stored on chain references a package by its id and a tag, e.g., <nfp:script src="main.js?tag=latest" />.
The root directory contains the package.json for managing the dependencies used by app/ and bootloader/.
app/-- source for the project's main app bundlebootloader/-- source for the project's bootloadermedia/-- assets used as inputs to the build processbuild.mjs-- a Node.js script that builds the output SVG filedeploy.mjs-- a Node.js script that uploads built app bundles to the chain as new packages versions
-
Install the project
yarn install
-
Set up environment variables
cp .env.example .env
-
Generate or import a private key
You can generate a new account by simply running
node deploy.mjswithout a value set for the private key env var.Or, you can import a private key from
secretcliusing the following command:secretcli keys export ACCOUNT_NAME --unarmored-hex --unsafe -
Build everything
For production:
yarn build
OR
For development:
yarn dev
While developing, you can use
yarn watch:devto automatically reload on file changes -
Deploy the app to chain
yarn deploy:app # simply calls `node deploy.mjs` -
Open the built SVG file in a web browser (
file://protocol works!) or preview in no-script mode using other means.
Outputs:
dist/nfp.svg- the built and minified SVG file- `dist/ngp.svg.gz - the gzipped, production-ready SVG meant for deployment on chain
dist/nfp.dev.svg- a developer-friendly SVG which links to styles and scripts instead of inlining them (be aware that this version is only intended for debugging within in a browser, linked assets do not work in no-script mode)dist/preview.html- a preview of embedding the SVG as an image in an HTML document (i.e., to preview in no-script mode)
For each task in package.json:
buildproduces production-ready outputdevproduces developer-friendly outputwatchis same as dev but with automatic reloading