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 (i.e., by injecting script elements). 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" />.
See MODULES.md for documentation on the NFP module system.
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
-
Install the nfp cli
yarn global add @nfps.dev/cli
-
Set up environment variables
nfp init
-
Import the account of an admin/minter
You can import a private key from
secretcliusing the following command:sed -i'' "s/^NFP_WALLET_PRIVATE_KEY=.*/NFP_WALLET_PRIVATE_KEY=\"$(secretcli keys export "${ACCOUNT_NAME}" --unarmored-hex --unsafe)\"/" .env
Mint a new token from this imported account:
nfp mint "${SOME_TOKEN_ID}"On success, the above command will update the env vars
NFP_OWNERandNFP_TOKEN_IDin the.envfile. -
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
nfp set-vk "password123" nfp package upload dist/app.js nfp package upload dist/storage.js --tags 1.x latest nfp storage owner put 'foo: "bar", baz: 25'
-
Open the built SVG file in a web browser (
file://protocol works!) or preview in no-script mode using other means. -
Configure a COMC host
If operating offline, or
x.s2r.shis not available, run a local COMC host and update your.envfile accordingly: e.g.,NFP_COMC_HOST="http://localhost:8080/". A COMC host is a page served from an HTTP(S) URL that is capable of communicating with Keplr on behalf of the NFP when it is served from thefile://protocol (Keplr only injects a content-script into HTTP(S) tabs). -
Connect your web extension wallet to the app
If using Keplr:
- for the testnet, make sure to accept the prompt to add the
pulsar-3testnet chain - reload the page and approve the connection request from the COMC host (e.g.,
https://x.s2r.shorhttp://localhost:8080) - make sure your wallet is funded. for the testnet: https://faucet-ui-pulsar3.vercel.app/
- for the testnet, make sure to accept the prompt to add the
-
Follow instructions to "Grant Allowance". This allows the Neutrino hot hot wallet to pay tx fees using the account of your web wallet.
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