Midnight.js v6.0.0 release notes
For the complete documentation index, see llms.txt
- Version: v6.0.0
- Date: 2026-12-03
- Environment: Mainnet, Preview, Preprod
- Node.js requirement: 22.12 or later
High-level summary
Midnight.js 6.0.0 is a major release for the ledger 9 stack. It moves ledger 9 contracts to Compact toolchain 0.37.0 and Compact runtime 0.22.0, and it refuses contract artifacts built with toolchain 0.36.x. Recompile your ledger 9 contracts when you upgrade. Midnight.js doesn't remove or rename any export of its own, but two cases that used to pass now throw. The Compact.js that it re-exports also drops CompactRuntime.sampleSigningKey.
The release also lets findDeployedContract check only the circuits you name, and it checks each ledger 9 call with the ledger before proving it. It hands back the private state that a failed transaction computed, and it takes a pino logger directly.
The networks didn't change for this release. They still run node 2.1.101, ledger 9.1.0.1, and indexer 4.4.101. The compatibility matrix lists Midnight.js 6.0.0 with Compact toolchain 0.37.0 and Compact runtime 0.22.0 for Mainnet, Preview, and Preprod. Midnight.js 5.0.x doesn't accept toolchain 0.37.0 output, so move Midnight.js and the toolchain together.
Audience
This release note is relevant for developers who:
- Build DApps with Midnight.js 5.0.x on Mainnet, Preview, or Preprod
- Compile ledger 9 contracts with Compact toolchain 0.36.0 or 0.36.1
- Maintain ledger 9 contracts that are already deployed
- Call contracts deployed before the ledger 9 upgrade
- Serve ZK artifacts to a browser DApp through
FetchZkConfigProvider - Test with testkit-js
Requirements
| Item | 5.0.3 | 6.0.0 |
|---|---|---|
| Compact toolchain for ledger 9 contracts | 0.36.0 or 0.36.1 (language 0.28) | 0.37.0 (language 0.29) |
| Compact runtime | @midnight-ntwrk/compact-runtime 0.21.0 | @midnight-ntwrk/compact-runtime 0.22.0 |
| Compact.js | @midnight-ntwrk/compact-js 3.0.2 | @midnightntwrk/compact-js 6.1.0 |
| Platform JS | @midnight-ntwrk/platform-js 3.0.0 | @midnightntwrk/platform-js 4.0.0 |
| Ledger package | @midnightntwrk/ledger-v9 1.0.2 | Unchanged |
| On-chain runtime | @midnightntwrk/onchain-runtime-v4 4.0.2 | Unchanged |
| Contracts deployed before the ledger 9 upgrade | Toolchain 0.31.x artifacts (Compact runtime 0.16) | Unchanged |
| Proof server | 9.0.2 | Unchanged |
| Wallet SDK | 2.0.1 | Unchanged |
| Node.js | 22.12 or later | Unchanged |
Midnight.js 6.0.0 is on npm under the @midnightntwrk scope only. The @midnight-ntwrk/midnight-js-* packages stop at 5.0.1.
Summary of updates
- Ledger 9 contracts move to Compact toolchain 0.37.0. Midnight.js 6.0.0 refuses artifacts built with toolchain 0.36.x (breaking).
- Compact.js and Platform JS move to the
@midnightntwrkscope, at 6.1.0 and 4.0.0. The@midnightntwrk/midnight-js-protocolsubpaths that re-export them keep their names. - The ledger 9 pins stay at the 5.0.1 set:
@midnightntwrk/ledger-v91.0.2 and@midnightntwrk/onchain-runtime-v44.0.2. findDeployedContracttakes an optionalcircuitIdslist and checks only those circuits.- The ledger checks each ledger 9 call before Midnight.js proves it. A call that the ledger would refuse fails early with
TxNotWellFormedError. TxFailedErrorcarries the private state that a failed call or deploy computed, onprivateState.- You can pass a pino instance directly as
loggerProvider, and the indexer provider takes an optionallogger. - Midnight.js refuses a call given
privateStateId: undefined(breaking). FetchZkConfigProviderreports a 401 or 403 from the artifact host as an error instead of a missing file (breaking).- testkit-js no longer writes the wallet seed to the log.
New features
Find a contract by the circuits you call
findDeployedContract refused a ledger 9 contract unless every circuit had a verifier key on chain. Pass circuitIds to check only the circuits you name. A DApp can then attach to a contract that deploys some circuits first and adds the rest later through maintenance updates.
const found = await findDeployedContract(providers, {
compiledContract,
contractAddress,
circuitIds: ['increment'],
});
await found.callTx.increment();
- A
callTxcall to a circuit that isn't in the list rejects withInvalidArgumentErrorbefore any proof. - An empty list, or a circuit that the contract doesn't declare, throws
InvalidArgumentErrorbefore anything is read from the chain. - The check runs once, when you find the contract. After a maintenance update adds a circuit, find the contract again with that circuit in the list.
- Without
circuitIds,findDeployedContractchecks every circuit, as before. The option applies to ledger 9 contracts only.
Ledger check before proving
Before Midnight.js proves a ledger 9 call, the ledger checks the unproven transaction. A call that the ledger would refuse now fails before the proof server does any work on it. It throws TxNotWellFormedError with the code MIDNIGHT_JS_C_TX_NOT_WELL_FORMED, and the ledger's own error is on cause.
Retrying the same call fails the same way. One case you can fix yourself: a ttlSeconds value past the network's time-to-live limit fails this check, so lower it.
The check skips balancing, proofs, signatures, and the transaction size limit, because those come after proving. It also skips the ledger's check that a call's declared gas fits the block limits. It doesn't cover ledger 8 calls, or the merged transaction of a contract-scoped transaction, yet.
Private state on a failed transaction
When a call or deploy fails with TxFailedError, the error now carries the private state that the operation computed, on privateState. For a call, that's the next private state. For a deploy, it's the private state from the constructor. Before 6.0.0, Midnight.js dropped it, and for a call it existed nowhere else.
Midnight.js doesn't store this state for you. With the FailFallible status, part of the transaction can be on chain, so read the chain first. Then store the state with your private state provider only if the operation landed. Like signingKey, the property isn't enumerable, so it stays out of Object.keys, object spread, and JSON.stringify.
Pass a pino logger directly
@midnightntwrk/midnight-js-types adds MidnightLogger, a logger with optional debug, info, warn, and error methods that take structured fields first and a message second. A pino instance fits it, and pino already fit loggerProvider. Pass pino directly instead of through the @midnightntwrk/midnight-js-logger-provider wrapper.
import pino from 'pino';
const logger = pino({ level: 'info' });
const providers = {
...otherProviders,
loggerProvider: logger,
publicDataProvider: indexerPublicDataProvider({ queryURL, subscriptionURL, logger }),
};
The indexer provider is built on its own, so pass the logger to it through the new logger option. Subscription transport warnings go there.
Fixed issues
- The
@midnightntwrk/midnight-js-logger-providerwrapper passed all the arguments of a log call to pino as one array. Log lines had nomsg, anErrorcame out as{}, and pino'sredactoption didn't hide the fields it named. The wrapper now forwards the arguments as given. - For a
FailFallibledeploy,TxFailedErrorsaid that the contract may exist on chain and that a second deploy would leave two copies. A deploy runs in the fallible phase, so that was wrong. When the record holds exactly one fallible segment, the message now says that the contract wasn't deployed, or that a maintenance update wasn't applied. Otherwise, it says that the operation may have landed and asks you to read the chain. - With two installed copies of
@midnightntwrk/midnight-js-utilsor@midnightntwrk/midnight-js-types, a failed read of the artifacts' runtime version could surface as a raw provider error instead ofEraMismatchError. Midnight.js now matches these errors by their code. - A logger that throws no longer replaces the original error of a contract-scoped transaction. The indexer provider's new
loggeroption has the same guard, so a logger that throws can't stop the socket from closing. - testkit-js logged the wallet's master seed in plain text at the info level, in
MidnightWalletProvider.build()and inFluentWalletBuilder.withRandomSeed(). Neither logs the seed now. Logs written by earlier versions still contain those seeds.build()still returns the seed inseeds.
Deprecations
These still work in 6.0.0. The source marks them for removal in the next major release.
| Deprecated | Use instead |
|---|---|
The @midnightntwrk/midnight-js-logger-provider package | Pass a pino instance as loggerProvider |
LogLevel and LoggerProvider.isLevelEnabled in @midnightntwrk/midnight-js-types | Nothing. Midnight.js doesn't read log levels |
RetainedLedgerEra and RETAINED_LEDGER_ERAS in @midnightntwrk/midnight-js-protocol/version | Exclude<LedgerEra, CurrentLedgerEra>, and LEDGER_ERAS filtered to leave out CURRENT_LEDGER_ERA |
Breaking changes
Midnight.js doesn't remove or rename any export of its own. The break is in the contract artifacts that Midnight.js accepts, plus two cases that used to pass and now throw. The Compact.js that Midnight.js re-exports also drops one name, covered in the note at the end of this section.
Ledger 9 contracts need Compact toolchain 0.37.0
Midnight.js reads the Compact runtime version from your compile output and uses it to pick the ledger. It reads compiler/contract-manifest.json, and falls back to compiler/contract-info.json for artifacts without a manifest, such as toolchain 0.31.x output. The versions it knows changed:
| Compact runtime in the artifacts | Built by | 5.0.3 | 6.0.0 |
|---|---|---|---|
| 0.16.x | Toolchain 0.31.x | Ledger 8 | Ledger 8 |
| 0.21.x | Toolchain 0.36.0 or 0.36.1 | Ledger 9 | Refused |
| 0.22.x | Toolchain 0.37.0 | Refused | Ledger 9 |
With artifacts from toolchain 0.36.x, a DApp on 6.0.0 fails in one of two places. Which one depends on the Compact runtime that the compiled contract loads. With runtime 0.22.0, importing the contract throws Version mismatch: compiled code expects 0.21.0, runtime is 0.22.0. With runtime 0.21.0, for example from a pin in your package.json, the import works. Every contract operation then throws EraMismatchError with the reason unknown-artifact-runtime-version. That includes deploy, find, call, and maintenance. The EraMismatchError message ends with the version it found:
EraMismatchError: These artifacts declare a compact-runtime this version of midnight-js places on no ledger era, so no pipeline can be chosen for them. Upgrade midnight-js to one that knows this toolchain, or rebuild the contract with a toolchain this version supports. The artifacts declare compact-runtime 0.21.0.
Recompile every ledger 9 contract with Compact toolchain 0.37.0. Toolchain 0.37.0 has its own breaking changes, so read the Compact toolchain 0.37.0 release notes first. Artifacts of contracts deployed before the ledger 9 upgrade aren't affected.
A recompile can change verifier keys
Toolchain 0.37.0 can compile the same source to a different circuit, and a different circuit has a different verifier key. In the Midnight.js repository's own test contracts, 9 of 52 verifier keys changed in the recompile, with no change to the contract sources.
For a contract that's already deployed, a changed key means the new artifacts no longer match the chain. findDeployedContract throws ContractTypeError and names the circuits. The contract's maintenance authority has to replace each changed key before you can call that circuit from 6.0.0. For the steps, see Upgrade. Until then, you can find the contract with circuitIds set to the circuits whose keys didn't change.
A contract deployed without a maintenance authority can't replace its keys. To call a circuit whose key changed, keep the contract's toolchain 0.36.x artifacts and call it with Midnight.js 5.0.3. You can also deploy the contract again as a new one. For background, see Recompiling a contract changes its verifier keys.
A call refuses privateStateId: undefined
A call that passes the privateStateId property with the value undefined now throws InvalidArgumentError. Before 6.0.0, a call to a contract deployed before the ledger 9 upgrade ran with no private state, which hid a missing setting. For a ledger 9 contract, submitCallTx already refused it, and createUnprovenCallTx now throws InvalidArgumentError instead of PrivateStateNotFoundError.
Before:
await submitCallTx(providers, {
compiledContract,
contractAddress,
circuitId: 'increment',
privateStateId: settings.privateStateId, // can be undefined
});
After:
await submitCallTx(providers, {
compiledContract,
contractAddress,
circuitId: 'increment',
...(settings.privateStateId !== undefined ? { privateStateId: settings.privateStateId } : {}),
});
Leaving the property out still runs the call with no private state. TypeScript already rejects the first form for a ledger 9 contract, so check your calls to older contracts, your JavaScript code, and your type casts.
A 401 or 403 from the artifact host is an error
FetchZkConfigProvider treated a 401 or 403 on compiler/contract-info.json or compiler/contract-manifest.json as a missing file. On the first, it surfaced as EraMismatchError with the reason artifact-era-undeclared. On the second, the provider treated the artifacts as having no manifest.
Now only a 404, or an HTML fallback page, means that the file is missing. Any other failed response is an error. Reading the runtime version throws ZkArtifactFetchError. Reading a key throws ZkArtifactIntegrityError when the host refuses the manifest, with the ZkArtifactFetchError on cause. When the host refuses the key file itself, reading it throws ZkArtifactFetchError.
Some hosts answer 403 for a file that doesn't exist, such as an S3 bucket without list permission. On those hosts, artifacts without a manifest now fail to load, including toolchain 0.31.x artifacts served with verify: 'require-if-present'. Make the host answer 404 for missing files.
The repository's breaking changes list also names the removal of a verifier key that the contract doesn't hold. That change is in Compact.js. submitRemoveVerifierKeyTx already refused this case in 5.0.3, with InvalidArgumentError or BlankVerifierKeySlotError, and it does the same in 6.0.0. It affects you only if you build maintenance updates with Compact.js directly. There, removeContractOperation now fails with ContractConfigurationError instead of building the removal.
Compact.js also removed CompactRuntime.sampleSigningKey, so it's gone from @midnightntwrk/midnight-js-protocol/v9/compact-js/effect. Use CompactRuntime.makeSampleSigningKey('schnorr') instead, and read the key's hex with CompactRuntime.signingKeyHex(key). The sampleSigningKey function that the Compact runtime exports is still there.
Upgrade
-
Install Compact toolchain 0.37.0.
compact update 0.37.0 -
Move every
@midnightntwrk/midnight-js-*package and@midnightntwrk/testkit-jsto 6.0.0 together. If yourpackage.jsonlists the Compact runtime, move it to 0.22.0. The runtime keeps its@midnight-ntwrkname, because the compiled contract imports it under that name.Before:
package.json{"dependencies": {"@midnightntwrk/midnight-js": "5.0.3","@midnight-ntwrk/compact-runtime": "0.21.0"}}After:
package.json{"dependencies": {"@midnightntwrk/midnight-js": "6.0.0","@midnight-ntwrk/compact-runtime": "0.22.0"}}If you're still on the
@midnight-ntwrk/midnight-js-*packages, rename the scope to@midnightntwrkinpackage.jsonand in every import.If you import Compact.js or Platform JS by name, or pin them through
overridesorresolutions, switch to@midnightntwrk/compact-js6.1.0 and@midnightntwrk/platform-js4.0.0 together. Compact.js 6.1.0 depends on exactly Platform JS 4.0.0. -
Recompile every ledger 9 contract, then check the runtime version in its artifacts.
Toolchain 0.37.0 implements language version 0.29.0. If a contract pins an earlier version, such as
pragma language_version 0.28;, the compiler stops withlanguage version 0.29.0 mismatch. Change the pragma first, for example topragma language_version >= 0.28;.compact compile src/counter.compact src/managed/countergrep '"runtime-version"' src/managed/counter/compiler/contract-info.jsonThe output names Compact runtime 0.22.0:
"runtime-version": "0.22.0",Leave the artifacts of contracts deployed before the ledger 9 upgrade as they are.
-
For each ledger 9 contract that's already deployed, call
findDeployedContractwith the new artifacts. If it throwsContractTypeError, the message names the circuits whose keys changed:The contract at '<address>' is not the expected contract type.Deployed verifier key differs from the local one: increment. The local artifacts were built from a different contract or a different version of it.Have the contract's maintenance authority replace the key of each named circuit, then find the contract again. Between the two transactions, the circuit has no key, so calls to it fail.
const newVerifierKey = await providers.zkConfigProvider.getVerifierKey('increment');await submitRemoveVerifierKeyTx(providers, compiledContract, contractAddress, 'increment');await submitInsertVerifierKeyTx(providers, compiledContract, contractAddress, 'increment', newVerifierKey); -
Check your code for the two cases under Breaking changes that now throw, and for
CompactRuntime.sampleSigningKeyif you call Compact.js through@midnightntwrk/midnight-js-protocol.
Run proof server 9.0.2 and Wallet SDK 2.0.1 with this release, unchanged from 5.0.1. The compatibility matrix lists this set for Mainnet, Preview, and Preprod.
Known issues
- A trie insert in the ledger can produce a malformed trie that fails to deserialize. The full fix needs a hard fork. See midnight-ledger#865.
- For a
FailFallibledeploy or maintenance update, theTxFailedErrormessage still says that some of the operation's effects may be on chain. That sentence sits right before the new one, which says that the contract wasn't deployed or the update wasn't applied. The new one is right. See midnight-js#1790. TxFailedErroris the only error that carries the computed private state. Midnight.js still drops that state when something else fails after submission, such as the wait for the transaction or a private state write. A ledger 9 deploy can also lose its signing key that way. See midnight-js#1807.