/midnight-skills:dynamic-midnight-walletfrom midnight-skills
Scaffolds a React + Vite TypeScript app integrating Dynamic.xyz Midnight wallets. Covers external (1AM extension) and embedded MPC wallets (social/email), three address surfaces (unshielded, shielded, DUST), balances, sendBalance routing, registerDust, and contract settlement via getWalletProvider().
Ships in midnight-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Versions: every pin in this skill comes from
references/versions.json, the repo's single source of truth (checked in CI). Resolve the current set at use time withreferences/volatile.md. Never install@latest.
Generate a React + Vite + TypeScript app that connects Midnight wallets through Dynamic.xyz (@dynamic-labs/midnight). Prefer this over hand-rolled window.midnight when the product already uses Dynamic auth/wallet UI.
Primary references:
@dynamic-labs/[email protected] + @dynamic-labs/[email protected] (+ @dynamic-labs/[email protected] for WalletAddressType). Dynamic ships fast: 5.20.0 (21 Nov 2026, with [email protected]) is current. Upgrade all three together and re-test, since this skill's code was written against 5.12.2.@midnight-ntwrk/[email protected] (no Midnight.js / ledger packages), so the external-wallet path works on Ledger 9 whenever the user's wallet (e.g. a Ledger 9 build of 1AM) does. Connector 4.1.0 is backwards-compatible. Embedded (WaaS) settlement runs on Dynamic's infrastructure, and its Ledger 9 support is not verifiable from the npm packages, so confirm with Dynamic before relying on it for mainnet dustBalance hooks below will read 0 until registration and generation happen again@midnightntwrk/midnight-js-dapp-connector-proof-provider (references/midnight-session.md)Key architecture notes:
A Midnight wallet is not a single address — three surfaces:
| Surface | Role | Dynamic API |
|---|---|---|
| Unshielded | Public address/state | wallet.address |
| Shielded | Private token pool | wallet.additionalAddresses (MidnightShielded / midnight_shielded) |
| DUST | Fee-generation state | wallet.additionalAddresses (MidnightDust / midnight_dust) |
NIGHT exists as both shielded and unshielded — different pools, not duplicate balances
Dynamic — connection lifecycle, connectors, address/balance accessors, send routing
1AM (external) — key custody, derivation, proving, signing, submission via @midnightntwrk/dapp-connector-api
Your app — deposit UX: surface both unshielded and shielded; DUST is generated, not deposited to
sendBalance routes by recipient prefix: mn_shield… → shielded, otherwise unshielded. No cross-pool transfers
Always guard with isMidnightWallet(wallet) before Midnight methods
Contract deploy/call with Dynamic's settlement provider is documented for embedded wallets (getWalletProvider()). External wallets use their own provider surface (see 1am-wallet/)
Relationship to other skills:
react-wallet-connector/1am-wallet/token-transfers/DynamicContextProvider + MidnightWalletConnectors (external) or DynamicWaasMidnightConnectors (embedded)sendBalance; for embedded add registerDust / optional contract providermy-dynamic-midnight-app/
├── index.html
├── package.json
├── tsconfig.json
├── tsconfig.app.json
├── tsconfig.node.json
├── vite.config.ts
├── .env.example
└── src/
├── main.tsx
├── App.tsx
├── MidnightWalletPanel.tsx
├── hooks/
│ └── useMidnightWallet.ts
└── vite-env.d.ts
Full content: references/scaffold-files.md. It covers scaffold commands plus package.json, vite.config.ts, TS configs, vite-env.d.ts, and main.tsx (sections 3-8). Open it when you reach this step.
import { DynamicContextProvider, DynamicWidget } from '@dynamic-labs/sdk-react-core';
import { MidnightWalletConnectors } from '@dynamic-labs/midnight';
import MidnightWalletPanel from './MidnightWalletPanel';
const environmentId = import.meta.env.VITE_DYNAMIC_ENVIRONMENT_ID;
if (!environmentId) {
throw new Error('Set VITE_DYNAMIC_ENVIRONMENT_ID in .env');
}
export default function App() {
return (
<DynamicContextProvider
settings={{
environmentId,
walletConnectors: [MidnightWalletConnectors],
}}
>
<header>
<h1>Midnight + Dynamic</h1>
<DynamicWidget />
</header>
<main>
<MidnightWalletPanel />
</main>
</DynamicContextProvider>
);
}
import { DynamicWaasMidnightConnectors } from '@dynamic-labs/midnight';
<DynamicContextProvider
settings={{
environmentId,
walletConnectors: [DynamicWaasMidnightConnectors],
}}
>
Dashboard: Chains & Networks → Midnight on, and Embedded Wallets → Security → Private Key Exports on.
src/hooks/useMidnightWallet.tsimport { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isMidnightWallet } from '@dynamic-labs/midnight';
import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
export function useMidnightWallet() {
const { primaryWallet } = useDynamicContext();
if (!primaryWallet || !isMidnightWallet(primaryWallet)) {
return { wallet: null, isConnected: false as const };
}
const shieldedAddress = primaryWallet.additionalAddresses?.find(
(a) => a.type === WalletAddressType.MidnightShielded,
)?.address;
const dustAddress = primaryWallet.additionalAddresses?.find(
(a) => a.type === WalletAddressType.MidnightDust,
)?.address;
return {
wallet: primaryWallet,
isConnected: true as const,
unshieldedAddress: primaryWallet.address,
shieldedAddress,
dustAddress,
};
}
import { isMidnightWallet } from '@dynamic-labs/midnight';
if (!isMidnightWallet(wallet)) {
throw new Error('This wallet is not a Midnight wallet');
}
Narrow before getFormattedBalances(), sendBalance(), or connector methods.
// Unshielded — main address
const unshieldedAddress = primaryWallet.address;
// Shielded + DUST — additionalAddresses
const shieldedAddress = primaryWallet.additionalAddresses?.find(
(a) => a.type === WalletAddressType.MidnightShielded,
)?.address;
const dustAddress = primaryWallet.additionalAddresses?.find(
(a) => a.type === WalletAddressType.MidnightDust,
)?.address;
Deposit UX: show unshielded and shielded. DUST is generated, not deposited to.
Cryptographic keys for circuits (external connector):
const { shieldedCoinPublicKey, shieldedEncryptionPublicKey } =
await primaryWallet.connector.getShieldedAddresses();
const { unshieldedBalance, shieldedTokenCount, dustBalance } =
await primaryWallet.getFormattedBalances();
// unshieldedBalance -> e.g. "3.0" (undefined if none)
// shieldedTokenCount -> distinct shielded token types with positive balance
// dustBalance -> { balance: string, cap: string } | undefined
const { unshieldedBalance, shieldedTokenCount, dustBalance, dustSyncing } =
await primaryWallet.getFormattedBalances();
if (dustSyncing) {
setTimeout(() => void refreshBalances(), 2500);
}
Individual getters:
await primaryWallet.getShieldedBalance(); // shielded NIGHT
await primaryWallet.getUnshieldedBalance(); // unshielded NIGHT
await primaryWallet.getDustBalance(); // { balance, cap }
Raw per-token amounts:
const { shielded, unshielded, dust } = await primaryWallet.getBalances();
src/MidnightWalletPanel.tsxFull content: references/wallet-panel.md. It covers the complete MidnightWalletPanel.tsx component. Open it when you reach this step.
sendBalance routes by recipient prefix (mn_shield… = shielded, otherwise unshielded). Same pool only.
await primaryWallet.sendBalance({
toAddress: 'mn_shield...',
amount: '1.5',
});
token.decimals is set)await primaryWallet.sendBalance({
toAddress: 'mn_addr...',
amount: '100000000',
});
await primaryWallet.sendBalance({
toAddress: 'mn_shield...',
amount: '50',
token: { address: 'tokenTypeHex', decimals: 6 },
});
const { serializedTransaction } = await primaryWallet.createTransferTransaction({
transfers: [
{
type: 'unshielded', // or 'shielded'
recipientAddress: 'mn_addr...',
amount: '100000000',
},
],
});
const finalizedTransaction =
await primaryWallet.signTransaction(serializedTransaction);
const { txHash } = await primaryWallet.submitTransaction(finalizedTransaction);
Stuck inputs after aborted builds:
await primaryWallet.revertTransaction(serializedTransaction);
await primaryWallet.revertAllPending();
// last resort: await primaryWallet.resetWalletCache();
const result = await primaryWallet.registerDust();
// 'registered' | 'already_registered' | 'already_has_dust' | 'no_utxos'
Fund unshielded NIGHT first. Registration does not mint DUST — it accrues over time. Poll getFormattedBalances() until dustBalance appears.
Embedded signing:
const signature = await primaryWallet.signMessage('Hello Midnight');
Contract half (circuits, witnesses, ZK proof) runs in your app via midnight-js. Settlement (balance, DUST, sign, submit) stays in the Dynamic iframe:
const walletProvider = await primaryWallet.getWalletProvider();
Wire into midnight-js providers (walletProvider + midnightProvider from Dynamic; you supply private state, indexer, zk config, proof server). Full pattern: Dynamic midnight-contracts + skills midnight-js/, 1am-wallet/.
For external 1AM, use the extension's own provider surface (1am-wallet/) — Dynamic's settlement provider docs are embedded-only.
index.html / .env.example / run<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Midnight + Dynamic</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
# .env.example
VITE_DYNAMIC_ENVIRONMENT_ID=
cp .env.example .env
# paste Environment ID
npm install
npm run dev
Open http://localhost:5173 → DynamicWidget → connect → panel shows three surfaces and balances.
| Layer | Owns |
|---|---|
| Dynamic | Connection lifecycle, connectors, MidnightWallet, address/balance accessors, send routing |
| 1AM (external) | Key custody, derivation, ZK proving, signing, submission |
| Your DApp | Deposit/receive UX (unshielded and shielded), pool display, DUST messaging |
| Symptom | Cause | Fix |
|---|---|---|
| Midnight missing in widget | Chain disabled | Enable Midnight → Chains & Networks |
| 403 on all methods (embedded) | Private Key Exports off | Embedded Wallets → Security → enable |
isMidnightWallet false | Wrong connector | Use MidnightWalletConnectors or DynamicWaasMidnightConnectors |
| Shielded / DUST missing | Still syncing | Retry; poll dustSyncing (embedded) |
| Send fails cross-pool | mn_addr ↔ mn_shield | Same pool only |
| Version mismatch | Mixed @dynamic-labs/* | Align midnight + sdk-react-core versions |
| Empty DUST | Not registered / low NIGHT | registerDust() after funding unshielded NIGHT (embedded) |
| Deploy works, calls fail | Proof server / ZK artifacts | See midnight-contracts pitfalls; first callTx needs proof server |
react-ts or write files from this skillVITE_DYNAMIC_ENVIRONMENT_IDMidnightWalletConnectors (external) or DynamicWaasMidnightConnectors (embedded)DynamicWidgetisMidnightWallet1am-wallet/ / midnight-js/ for contract deploy beyond connection| Need | Skill |
|---|---|
| DApp Connector without Dynamic | react-wallet-connector/ |
| Contract deploy + circuits (1AM) | 1am-wallet/ |
| Token units & pools | token-transfers/ |
| SDK providers | midnight-js/ |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub kali-decoder/midnight-skills --plugin midnight-skills43 skills in this plugin
/1am-walletIntegrate the 1AM wallet for dust-free contract deployment and transaction flow on Midnight Network. Use this skill whenever a user is building a Midnight Network dApp, connecting to the 1AM browser extension, deploying or calling a Compact contract, handling ZK proving, setting up providers, or asking about dust-free transaction flow. Also use it for indexer patching, private state providers, payload encryption, or any question involving window.midnight['1am']./android-example-votingBuild a voting/poll dApp on Midnight Network using the Kuira Android SDK — Compact smart contract with create/cast/close circuits, passkey-derived identity, embedded wallet, Compose UI, reactive ledger reads via observeLedger(), and on-device ZK proving. Use when building a poll or voting dApp targeting Android./ankr-midnightIntegrate Ankr as a Midnight Network RPC provider for testnet and mainnet. Covers creating an Ankr project, copying HTTPS/WSS endpoints with API key, wiring the node URL into midnight-js / multinetwork configs, and calling Midnight JSON-RPC methods (midnight_*, system_*, chain_*, state_*). Use when the user asks about Ankr + Midnight, Ankr.js for Midnight, Ankr RPC endpoint, or replacing public Midnight RPC with Ankr.
/compactWrite, reason about, and debug Compact smart contracts for the Midnight blockchain. Use this skill whenever a user asks about Compact syntax, ledger state, witnesses, circuits, disclosure, ZK patterns, data types, standard library functions, security patterns, nullifier design, Merkle trees, or anything related to writing .compact files. Also trigger for questions about compiling contracts, debugging circuit errors, choosing between ledger ADTs, and implementing privacy-preserving patterns like commitments, hash-based auth, and anonymous membership proofs./compact-language-engineeringBuild and maintain language tooling for Midnight's Compact language (parsers, grammars, syntax highlighters, formatters, linters, language servers, IntelliJ/Grammar-Kit plugins, tree-sitter grammars) without changing what the language accepts. Use this skill when a user asks to write or fix a Compact grammar, port the grammar to tree-sitter, Grammar-Kit, JFlex, ANTLR, Lezer, or TextMate, check operator precedence or associativity, track down parser ambiguities or nullable and left-recursive rules, generate parser regression tests, compare a third-party parser against the compiler, or build an LSP or editor extension for `.compact` files. Also use it for questions like "what tokens does Compact have", "is `/` or unary minus valid Compact", "why does my highlighter break on block comments", "tree-sitter-compact rejects valid code", or "how does the Nite language server get its diagnostics".
/dust-gas-sponsorshipLet one wallet pay Midnight transaction fees for another wallet's transaction, so users with zero DUST can transact from their first click. Use whenever a dApp onboards new users, offers a free tier, or covers usage for its users: the two-sided sponsorship flow (user proves and binds, sponsor adds DUST and submits), the sponsor service and its acceptance policy, sponsor economics and monitoring, and the hosted alternatives (NIGHTGATE, Capacity Exchange).Other plugins' skills for the same job