@dignetwork/next-plugin-dig
v0.1.0
Published
A Next.js static-export adapter that makes DIG a first-class deploy target: a window.chia dev shim for `next dev`, plus a publish step that ships the static export (out/) to a DIG capsule via `digstore deploy`, honoring dig.toml. Deploy to a network no ho
Downloads
166
Maintainers
Readme
@dignetwork/next-plugin-dig
A Next.js static-export adapter that makes DIG a first-class deploy target. Build with Next, deploy the static export to a DIG capsule — a network no host can read, change, or take down — on Chia.
It does two things:
- Dev wallet, for free. Helpers inject the
@dignetwork/dig-sdkwindow.chiadev shim into your app<head>duringnext dev— the same injected-provider contract the SDK'sChiaProviderdetects in production — so you can develop the wallet path without the DIG Browser or an extension. The shim guards on a real wallet (the DIG Browser always wins) and never fakes a signature. - Publish to a capsule.
digDeploy()ships your static export (out/) to a DIG capsule viadigstore deploy, printing thechia:/// DIGHUb URL. Publishing spends $DIG, so it is a deliberatepublishstep — never part ofnext build.
npm i -D @dignetwork/next-plugin-digStatic export only. DIG hosts a static, content-addressed capsule (no server runtime), so your Next app must use
output: "export". Server components/handlers, ISR, and image optimization that need a server aren't available on a static capsule.
Quickstart
1. Configure static export in next.config.mjs:
/** @type {import('next').NextConfig} */
export default {
output: "export", // writes the static site to out/
};2. Inject the dev wallet in your root layout, gated on dev so it never ships to production:
// app/layout.tsx
import Script from "next/script";
import { digNextDevShimScript } from "@dignetwork/next-plugin-dig";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
{process.env.NODE_ENV !== "production" && (
<Script id="dig-dev-wallet" dangerouslySetInnerHTML={{ __html: digNextDevShimScript() }} />
)}
</head>
<body>{children}</body>
</html>
);
}Run next dev and your app now has a window.chia to develop against (a clearly-fake mock address
that refuses to sign — so you always know it's the dev stub).
3. Add your store config to dig.toml:
store-id = "<your 64-hex store id>"
output-dir = "out" # Next's static-export dir (the adapter's default)
message = "deploy from next"4. Add a publish script that builds, then deploys:
// package.json
{
"scripts": {
"deploy": "next build && node -e \"import('@dignetwork/next-plugin-dig').then(m=>m.digDeploy())\""
}
}export DIGSTORE_DEPLOY_KEY=<from `digstore deploy-key export`>
npm run deploydigDeploy() defaults outputDir to out, reads dig.toml + DIGSTORE_* env, then runs
digstore deploy --json to advance the on-chain root, stage out/, and push the new capsule. It
returns { capsule, storeId, root, chiaUrl, digUrl, hubUrl, pushed } — chiaUrl is the
chia://<storeId>:<rootHash>/ address a user clicks to open the app (digUrl is a deprecated alias
of the same chia:// value); hubUrl is the DIGHUb view page.
Prereq:
digstoremust be installed and onPATH(the canonical deployer — the adapter never hand-rolls a deploy or a spend). See the install docs.
API
Dev shim
| Helper | Returns | Use |
|---|---|---|
| digNextDevShimScript(options?) | the eval-free script body (no <script> tags) | Next's <Script dangerouslySetInnerHTML> or a custom _document. |
| digNextDevShimTag(options?) | a ready <script>…</script> string | raw HTML injection. |
options.address sets the mock receive address the shim returns. Always gate on
process.env.NODE_ENV !== "production".
digDeploy(options?, deps?): Promise<DeployResult>
Deploy the static export. Call from a publish script after next build. Defaults outputDir to
out; an explicit outputDir (or DIGSTORE_OUTPUT_DIR / dig.toml's output-dir) overrides it.
Other options: storeId, message, network, remote, waitTimeout, cwd, digstoreBin.
Precedence is options > DIGSTORE_* env > dig.toml > default. On failure it throws a coded
DigAdapterError.
version() / capabilities()
import { version, capabilities } from "@dignetwork/next-plugin-dig";
version(); // "0.1.0"
capabilities(); // { name, version, framework: "next", exportDir: "out", features, errorCodes, docs }Error codes
The publish path always throws a DigAdapterError with a stable .code:
| Code | When |
|---|---|
| DIGSTORE_NOT_FOUND | digstore is not installed / not on PATH. |
| DEPLOY_FAILED | digstore deploy exited non-zero. |
| DEPLOY_OUTPUT_UNPARSEABLE | digstore deploy --json output couldn't be parsed into a capsule. |
| INVALID_ARGUMENT | A malformed argument. |
import { digDeploy, isDigAdapterError } from "@dignetwork/next-plugin-dig";
try {
await digDeploy();
} catch (e) {
if (isDigAdapterError(e, "DIGSTORE_NOT_FOUND")) console.error("Install digstore first.");
else throw e;
}The full catalogue is exported as DIG_ADAPTER_ERROR_CODES.
License
MIT.
