/midnight-skills:dust-gas-sponsorshipfrom midnight-skills
Implements DUST gas sponsorship for Midnight dApps so new users can transact without holding DUST. Covers the two-sided sponsorship flow, sponsor service with acceptance policy, wallet sizing, and hosted alternatives like NIGHTGATE.
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.
Every transaction on Midnight pays its fee in DUST, and DUST only comes from NIGHT that was registered for DUST generation, held over time. A brand-new wallet has zero DUST and cannot submit a single transaction, including one that moves no funds. DUST sponsorship removes that wall: the user authorizes the action, a sponsor wallet pays the DUST fee, and the two roles never mix. The result is a gasless experience for the user and a fee the sponsor controls.
What this skill produces:
Safety note (do not hide from the user):
Ledger 9 note: this skill is written for Ledger 9: Wallet SDK
2.0.1, Midnight.js 5.0.1 in the reference example (the live
references/versions.json pin is 5.0.2; check it before pinning),
indexer 4.4.101, Compact toolchain 0.36.1. The reference example
predates nothing: the official docs guide was published 24 Nov 2026.
Older sponsorship write-ups (May 2026, Wallet SDK 1.x) teach the same
two-phase mechanism but pre-Ledger 9 call shapes; do not mix their
code with this skill's.
Verified sources (checked 24 Nov 2026):
examples/private-party in
midnight-examples (read 24 Nov 2026): src/sponsor.ts,
src/wallet.ts, docs/SPONSORSHIP.md,
scripts/sponsor-service.ts, src/test/sponsorship.test.tsNEEDS CHECK before this skill ships:
Relationship to other skills:
dust/ covers DUST mechanics: registration, parameters, fee
estimation, multi-transaction locking, cNIGHT, and the Ledger 9
reset. Read it first if you have not worked with DUST. This skill
covers only who pays, not how DUST works.midnight-js/ covers the providers and the wallet SDK this skill
builds on.compact/ covers writing the contract whose authorization rule
makes sponsorship safe (section 2).dynamic-midnight-wallet/ covers the Dynamic abstraction path,
which configures a DUST interface for passkey and social-login
users.gero-wallet/ covers in-wallet DUST generation and Gero's
sponsored-fee support.indexer/ covers looking a submitted transaction up by its
ledger hash.DUST is a shielded, non-transferable resource. It cannot be bought,
sent, or airdropped. There is no transferDUST() call. It is
generated only by NIGHT that was registered for DUST generation, and
the ledger keeps a Registration Table linking NIGHT public keys to
DUST public keys. A DUST UTXO is created only when a NIGHT UTXO is
created and its key has an entry in that table.
So a wallet can hold plenty of NIGHT and still be unable to submit a single transaction. If its key was never registered, its NIGHT generates no DUST, and with zero DUST there is no fee it can offer, even for a transaction that moves no funds at all. That is the cold-start problem, and sponsorship is the fix: it is the only mechanism that pays fees for another wallet.
One bootstrap exists without a sponsor, worth knowing so you can tell
when sponsorship is the right tool. A first-time DustRegistration
carries an allowFeePayment field, a Speck-denominated allowance, not
a boolean flag, which lets the registration draw on retroactively
generated DUST to pay for itself. It is limited: only not-yet-
generating NIGHT UTXOs spent in the transaction's guaranteed section
count toward it, the allowance cannot exceed what those inputs
virtually accrued, and it covers that one transaction. Sponsorship
covers everything else.
Units, so the numbers in the logs make sense: 1 NIGHT = 10^6 STAR, 1 DUST = 10^15 SPECK. Every DUST and NIGHT amount from the ledger, the wallet SDK, and the indexer is in those units.
| Role | Holds | Can do | Cannot do |
|---|---|---|---|
| User | The contract secret, zero DUST | Prove and authorize the action | Pay the fee |
| Sponsor | NIGHT registered for DUST generation | Add a DUST fee offer and submit | Act as the user, alter the sealed transaction, or reach the user's secret |
Three mechanisms enforce the separation:
checkIn circuit requires
commitAddress(_secret, address.bytes) to match the RSVP on the
ledger. Only a caller who knows the secret can produce a valid
proof, so the sponsor's money buys nothing but the fee.FinalizedTransaction the
sponsor can add a DUST fee offer to, and nothing else.Never authenticate with
ownPublicKey(). It is a witness: the prover's machine chooses its return value, and the protocol never checks it against the signing wallet. Any check built on it is bypassable, by the sponsor or by anyone else. Authorization must come from proving knowledge of a secret, as the reference contract does. UseownPublicKey()only to route tokens to the caller.ownPublicKey()always returns the prover's key, not the sponsor's, which is also why it is the wrong key for routing DUST change back to the sponsor.
The split is enforced by one option, tokenKindsToBalance. Omit it
and it defaults to 'all', the ordinary self-paying path that
balanceTx uses.
| Party | Method | tokenKindsToBalance | Pays for |
|---|---|---|---|
| User | balanceUnboundTransaction | ['shielded', 'unshielded'] | Its own value |
| Sponsor | balanceFinalizedTransaction | ['dust'] | The transaction fee |
The user is always the prover, so the secret that authenticates the caller never reaches the sponsor. If the call moves user value, like the reference example's entry fee, that value still comes from the user's balance. Sponsorship covers fees, not funds.
Order matters, and it is the whole security argument. The user proves, balances, signs, and finalizes first:
| Guarantee | Why it holds |
|---|---|
| The sponsor cannot alter the call | The transaction is bound before handoff; the network rejects modifications |
| The sponsor cannot reach the secret | The user generated the proof; only the proof travels |
| The sponsor cannot act as the user | The contract authenticates by secret, which the sponsor does not hold |
| The user cannot spend the sponsor's funds | The sponsor balances only ['dust'], signs its own additions, and applies policy first |
| DUST cannot be extracted from the sponsor | DUST is not transferable; it can only be spent on fees the sponsor approves |
If the user hands over an unbalanced or unsigned transaction, the receiving side could reshape it. Balance, sign, and finalize on the user's side before anything leaves the user's machine.
From src/sponsor.ts in the reference implementation. The hex
string this returns is the network boundary: in production this
function runs where the user's keys live, such as a browser wallet.
export async function prepareSponsoredCall<
C extends Contract.Any,
PCK extends Contract.ProvableCircuitId<C>,
>(
logger: Logger,
user: MidnightWalletProvider,
providers: PartyProviders,
call: Ledger9CallTxOptionsWithPrivateStateId<C, PCK>,
): Promise<string> {
const unsubmitted = await createUnprovenCallTx<C, PCK>(providers, call);
// Proving happens here, on the user's side, which is why the secret
// that authenticates the caller never reaches the sponsor.
// Midnight.js 5 proof providers take and return era-tagged
// transaction handles.
const unboundTx = await providers.proofProvider.proveTx(unsubmitted.private.unprovenTx);
// Balance only the user's own value side (no DUST), sign, and bind.
const finalized = await user.balanceOwnValueAndFinalize(unboundTx);
return toHex(finalized.serialize());
}
Note what is not here: no DUST, no fee estimation, no sponsor keys.
A wallet with zero DUST can run every line. Inside
balanceOwnValueAndFinalize (src/wallet.ts), the wallet calls
balanceUnboundTransaction with tokenKindsToBalance: ['shielded', 'unshielded'], then signRecipe, then
finalizeRecipe. The method takes an era-tagged
LedgerTransaction<'Unbound'> handle and a TTL that defaults to one
hour.
The user needs a proof server and their own private inputs. They do not need DUST.
From src/sponsor.ts. Typically a small backend service, which can
apply acceptance policy, such as rate limits and allowlists, before
spending anything.
export async function sponsorAndSubmit(
logger: Logger,
sponsor: MidnightWalletProvider,
userTxHex: string,
): Promise<string> {
// The marker triple matches FinalizedTransaction =
// Transaction<SignatureEnabled, Proof, Binding>.
const userTx = Transaction.deserialize<SignatureEnabled, Proof, Binding>(
'signature',
'proof',
'binding',
fromHex(userTxHex),
);
// Attach a DUST fee offer paid by the sponsor, then submit.
const sponsored = await sponsor.addDustFeesAndFinalize(userTx);
const txId = await sponsor.submitTx(sponsored);
return txId;
}
Inside addDustFeesAndFinalize (src/wallet.ts), the wallet calls
balanceFinalizedTransaction with tokenKindsToBalance: ['dust'],
then signRecipe, then finalizeRecipe. The sponsor is a payer,
never an author.
Copy the deserialize call exactly: reconstructing the user's
transaction needs explicit type arguments, because the marker triple
alone infers a wider type that is not assignable to
FinalizedTransaction.
The sponsor needs NIGHT that is registered for DUST generation. Plain NIGHT is not enough, an unregistered sponsor is just as stuck as the user it is trying to help.
The reference example ships the sponsor as a small HTTP service
(scripts/sponsor-service.ts): GET /health and POST /sponsor
taking { "tx": "<hex>" }. The bundled service is a shape, not a
production service: it does no authentication, no rate limiting, no
per-request cap, and no check that the transaction targets your
contract. Add all four before the endpoint is reachable:
Do not let a transaction sit in a queue on the sponsor's side. The
real deadline is the intent TTL fixed when the transaction is
constructed, not the ttl passed on the user's balancing call, that
one is inert once 'dust' is excluded. A queued transaction can
expire before the sponsor touches it.
Full content: references/sponsor-economics.md. It covers cost model, pricing, abuse limits, and budget monitoring for a sponsor. Open it when you reach this step.
In examples/private-party, Dave is a party guest who holds NIGHT
for the entry fee but never registered for DUST generation, so his
DUST balance is exactly zero. Alice, the organizer, sponsors her
guests.
git clone https://github.com/midnightntwrk/midnight-examples.git
cd midnight-examples
yarn install && yarn compile
cd examples/private-party
yarn env:up # start the local environment
yarn wait:dust # wait until the sponsor wallet has generated DUST
yarn test:sponsorship # run the sponsored flow, including the negative cases
yarn sponsor:serve # or run the sponsor as an HTTP service
| File | What it contains |
|---|---|
src/sponsor.ts | prepareSponsoredCall (user side) and sponsorAndSubmit (sponsor side) |
src/wallet.ts | The role-specific balancing methods |
src/test/sponsorship.test.ts | Security validation: the sponsored happy path, plus proof that the payer cannot act and the actor cannot pay |
scripts/sponsor-service.ts | The sponsor as a small HTTP service |
The suite proves the premise before it demonstrates the fix: it
asserts that Dave holds NIGHT, that every one of his UTXOs reports
registeredForDustGeneration === false, and that his DUST balance
is 0n. It then shows him RSVPing and checking in anyway, and
re-asserts his DUST is still exactly zero afterwards. The headline
test prints one transaction, two payers: Dave's NIGHT falls by
exactly the 5 STAR entry fee, his DUST never moves off zero, and
Alice's DUST is what fell. The negative test has Alice attempt
checkIn with Dave's address and her own secret; it fails with
"You are not on the list".
To adopt the pattern, swap in your own smart contract. Your contract supplies the authorization rule; the two functions and their ordering stay the same.
Run your own sponsor when the fees are core to your product and you want full control of policy and cost. Use hosted sponsorship when you want gasless UX without operating a sponsor wallet.
NIGHTGATE, by ODATANO, exposes Midnight as an OData V4 API with
sponsored transactions: anchor, attest, and prove actions run with
no NIGHT or DUST needed from the caller. Packages
@odatano/nightgate (0.46.3) and @odatano/nightgate-mcp
(0.23.1), versions as of 24 Nov 2026. Networks: Midnight Preprod
and Preview; mainnet soon. A key made by signing in with a Cardano
wallet starts free, 300 calls for 90 days. A forwarded call costs
1, an indexer subscription 5; metadata and the verify lane are
free. Top-ups are paid with tNIGHT through an m402 payment vault on
Midnight, built with @odatano/nightgate-tx on the user's machine;
with a key, the platform sponsor pays the tDUST of the vault's
deposit and pay calls. The MCP server carries 28 tools plus 9
for analytics, including sponsor_swap, and scoped, budgeted
bearer tokens for AI agents instead of a full user key.
NIGHTGATE is the hosted path for document anchoring, attestations, and shielded transfers. It is not a replacement for the self-hosted flow when your dApp needs its own contract calls sponsored under its own policy.
The Capacity Exchange, built by Sundae Labs and live since August 2026, lets users settle transaction fees on supported Midnight applications using USDM, Moneta's 1:1 USD-backed stablecoin, instead of DUST. The exchange converts the alternative token payment into the network's required execution resource behind the scenes, through what Sundae Labs describes as a decentralized market of sponsors. Users with only a passkey or social login can transact, their DUST costs sponsored by the dApp itself or paid for with assets from other chains.
What this means for a builder today: if your app is supported, your users can pay fees in USDM without holding NIGHT or DUST. What it does not mean: there is no public integration surface verified for this skill, no SDK, repo, or integration guide was found on 24 Nov 2026, so this skill cannot teach adding Capacity Exchange support to an app yet. See the NEEDS CHECK at the top.
Gero Wallet 2.7.1 added sponsored DUST fees and USDM support: one
Midnight wallet can use its DUST to sponsor fees for another. A
pilot lets developers sponsor fees through an API, but no endpoint
or documentation was found on 24 Nov 2026, so treat the API as a
pilot, not a live integration. The gero-wallet/ skill covers
Gero's Ledger 9 status, which is itself still NEEDS CHECK.
Submission failures surface as 1010: Invalid Transaction: Custom error: N.
| Code | Name | Fix |
|---|---|---|
170 | InvalidDustSpendProof | Wait for the sponsor wallet to sync, then add the DUST fee offer again and submit; a wallet that pays the fee before it has synced every DUST event gets this rejection |
173 | InsufficientDustForRegistrationFee | Wait for generation before registering; see waitForGeneratedDust in the wallet SDK |
196 | DustDoubleSpend | Stale wallet view reused spent DUST; resync the sponsor wallet and rebuild |
| Symptom | Fix |
|---|---|
could not balance dust on the sponsor side | The sponsor's DUST does not cover fee plus overhead. Check the wait-for-dust step succeeded, and remember DUST accrues over time rather than appearing at once |
| The user's balancing step fails | If the circuit moves value, the user must still be able to fund that. Sponsorship pays the fee, not the payload |
| The sponsored transaction expires | The intent TTL fixed at construction is the real deadline. Do not queue transactions on the sponsor's side |
| Nondeterministic balancing failures in tests | Suites sharing one devnet and one sponsor wallet must not run in parallel; concurrent spends of the same UTXOs conflict |
'dust' in the user's tokenKindsToBalance.
Fails if the user has no DUST, which is the whole point of
sponsorship. The user balances ['shielded', 'unshielded'] only.['dust', 'shielded', 'unshielded'] on the sponsor side causes
double-spend errors. The sponsor balances ['dust'] only.transferDUST(). Sponsorship is the only way to cover fees for
another wallet.ownPublicKey(). It is a prover-chosen
witness, bypassable by design. Authenticate by secret (section 2).What SKILL.md sets; muted values are Claude Code's defaults
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".
/dynamic-midnight-walletScaffold a React + Vite TypeScript app with Dynamic.xyz Midnight wallets (@dynamic-labs/midnight). Covers external wallets (1AM extension via MidnightWalletConnectors) and embedded MPC wallets (social/email via DynamicWaasMidnightConnectors): three surfaces (unshielded, shielded, DUST), balances, sendBalance routing, registerDust, and embedded contract settlement via getWalletProvider(). Use when the user asks about Dynamic + Midnight, DynamicWidget Midnight, shielded/unshielded/DUST addresses in Dynamic, or replacing hand-rolled window.midnight with Dynamic.
Other plugins' skills for the same job