Shared accounting concepts do not make Ledger 2.x clients wire-compatible with the target. The target serves business endpoints under /v3 and does not expose a Ledger 2.x compatibility API.
Update and test clients before the production cutover. During mirroring, point non-production readers at the target; keep production writes on Ledger 2.x.
Build a workflow inventory#
Review behavior, not only endpoint names. For every workflow, record:
| Contract area | What to verify |
|---|---|
| Endpoint | Method, /v3 path, ledger name, and protocol. |
| Authentication | Issuer, audience, bearer token, and required read/write scope. |
| Request | Field names, amount encoding, metadata types, and mutually exclusive inputs. |
| Response | Wrapper, field names, post-commit volume snapshots, and absent fields. |
| Pagination | Cursor direction, page size, continuation value, and termination condition. |
| Filtering | Filter syntax, type conversion, and required indexes. |
| Errors | HTTP or gRPC status, domain reason, retryability, and conflict handling. |
| Idempotency | Key construction, scope, payload reuse, and retention assumptions. |
| SDK | Package major, generated method, numeric type, and timestamp type. |
| Observability | Correlation, audit lookup, metrics, and alert ownership. |
Cover create, revert, account reads, transaction reads, metadata, filters, pagination, bulk, Numscript, and events when your application uses them.
Update the base endpoint and authentication#
HTTP calls move from Ledger 2.x paths to /v3/{ledgerName}/.... Look up each call in the Endpoint Map: some change method or merge into another endpoint, and some have no equivalent. Send the target access token in the standard header:
Authorization: Bearer <access-token>Do not reuse a Ledger 2.x token without verifying its issuer, audience, and scopes against the target. Test from every application environment, including workers and scheduled jobs.
Use Authentication to map target identities and effective scopes before changing an application endpoint.
HTTP and gRPC do not expose every operational capability symmetrically. Select the protocol per workflow and keep cluster operations out of normal application clients.
Update transaction writes#
A transaction request declares exactly one content source:
- explicit
postings; - an inline Numscript
script; - a
scriptReferenceto a saved program.
Use the Idempotency-Key HTTP header for request idempotency. Do not add a body-level idempotency key.
Ledger 2.x transaction response fields for pre-commit and effective volumes are not part of the target contract. The target computes and returns postCommitVolumes unconditionally; there is no volume-expansion parameter to opt into. Read it at data.transaction.postCommitVolumes on create and at data.revertTransaction.postCommitVolumes on revert.
postCommitVolumes is an immutable snapshot taken at that transaction's sequence. It is never recomputed from later state, so it is not a current balance. If an application needs durable current balances, read the affected account or run the required aggregate query instead of reusing a write response.
Redesign idempotency keys#
Idempotency covers more target operations and uses a cluster-level namespace. A key that was treated as independent per Ledger 2.x ledger can conflict when reused on the target.
The observable failure is specific: when a key is reused anywhere in the cluster for different request content, the target rejects the request with HTTP 409 and errorCode: IDEMPOTENCY_KEY_CONFLICT. Assert on that pair in test cases 2 and 5 below. A key is at most 256 bytes. Keys expire after the cluster's --idempotency-ttl, which defaults to 24 hours and never expires when set to 0; a retry sent after that window re-executes the request instead of replaying the first outcome.
Construct keys from stable business identity, for example:
create-transaction:tenant-42:main:payment-018f1Test all of these cases:
- same key and same payload;
- same key and a different payload;
- a retry after a client timeout;
- the same business reference with a new idempotency key;
- the same key accidentally reused for another ledger or operation.
See Idempotency and References for the target request and conflict behavior.
Replace Ledger Schema workflows#
Ledger 2.x combined several concerns behind one schema API. The target models them independently:
| Ledger 2.x responsibility | Target resource |
|---|---|
| Validate account addresses | Account types and enforcement mode |
| Define metadata fields | Typed metadata schema |
| Reuse transaction templates | Versioned Numscript library |
| Reuse query templates | Prepared queries |
There is no single schema version that selects all four resources for a transaction. Update deployment and application ownership for each resource you use.
Move a transaction template to the Numscript library#
This example moves one Ledger 2.x transaction template to a saved Numscript program. The same steps apply to every template in a schema's transactions map: each template becomes a program of the same name.
The Ledger 2.x template#
In Ledger 2.x, the DEPOSIT template lives in schema v1.0.0, inserted with POST /v2/{ledger}/schemas/v1.0.0:
{ "chart": { "world": {}, "users": { "$userId": { "wallet": {} } } }, "transactions": { "DEPOSIT": { "description": "Fund a user wallet", "script": "vars {\n account $user\n}\nsend [COIN 10] (\n source = @world\n destination = $user\n)" } }}The caller names the template in script.template and pins the schema with the schemaVersion query parameter:
curl --request POST "$V2_URL/v2/$LEDGER_NAME/transactions?schemaVersion=v1.0.0" \ --header "Content-Type: application/json" \ --data '{"script":{"template":"DEPOSIT","vars":{"user":"users:alice:wallet"}},"reference":"DEP-2024-001"}'Save the program#
In Ledger 3.0, the template's script becomes a program in the ledger's Numscript library:
vars { account $user}send [COIN 10] ( source = @world destination = $user)Save it as DEPOSIT version 1.0.0 with PUT /v3/{ledgerName}/numscripts/{name}. The body takes content and version, both required, and the version must be an exact major.minor.patch. The template's description goes in the optional description field:
jq --null-input \ --arg content $'vars {\n account $user\n}\nsend [COIN 10] (\n source = @world\n destination = $user\n)' \ --arg description "Fund a user wallet" \ '{content: $content, version: "1.0.0", description: $description}' \ | curl --fail-with-body --silent --show-error \ --request PUT "$LEDGER_URL/v3/$LEDGER_NAME/numscripts/DEPOSIT" \ "${CURL_AUTH[@]}" \ --header "Content-Type: application/json" \ --header "Idempotency-Key: $LEDGER_NAME:numscript:DEPOSIT:1.0.0" \ --data @-Ledger parses the program before saving it and returns 201 Created. The idempotency key starts with the ledger name because keys are shared across the cluster: without it, saving DEPOSIT to a second ledger reuses the key for a different request and fails with 409. The description belongs to version 1.0.0: reads of the program return it, and changing it means saving a new version. It is limited to 1024 bytes of UTF-8 and cannot contain control characters other than newline and tab. Ledger rejects other values with 400 and reason VALIDATION. The chart moves separately, to account types.
Call it with scriptReference#
Replace script.template with scriptReference, which takes the program name, an exact version, and vars:
curl --fail-with-body --silent --show-error \ --request POST "$LEDGER_URL/v3/$LEDGER_NAME/transactions" \ "${CURL_AUTH[@]}" \ --header "Content-Type: application/json" \ --header "Idempotency-Key: $LEDGER_NAME:DEP-2024-001:create" \ --data '{"scriptReference":{"name":"DEPOSIT","version":"1.0.0","vars":{"user":"users:alice:wallet"}},"reference":"DEP-2024-001"}'Ledger runs DEPOSIT version 1.0.0 and returns 201 Created with the transaction. The request carries no schemaVersion: account types and typed metadata apply as currently configured, not as of a version.
Pin a version#
A Ledger 2.x caller that pinned schemaVersion=v1.0.0 pinned the whole schema, template included. In Ledger 3.0, the caller pins the program alone, in scriptReference.version:
| Ledger 2.x | Ledger 3.0 |
|---|---|
?schemaVersion=v1.0.0 on every write | "version": "1.0.0" in scriptReference. No v prefix |
| A new schema version for any template change | A new version of the changed program only |
Callers move by changing schemaVersion | Callers move by changing scriptReference.version |
scriptReference.version accepts an exact version or latest. Partial selectors such as 1 or 1.0, and an omitted version, are rejected with 400. Pin an exact version in production: latest re-resolves to the greatest stored version on every execution.
Publish a change#
The library is append-only, like Ledger 2.x schema versions. A published version cannot be edited or deleted, and saving a version that already exists fails with 409. To change DEPOSIT, save 1.1.0 and move callers to it.
To roll back callers that pin an exact version, set their scriptReference.version back to 1.0.0. Callers on latest follow the greatest stored version, so rolling them back means publishing a higher version, such as 1.2.0, with the 1.0.0 content.
See Reuse and Version Numscript Programs for version resolution, usage tracking, and error handling.
Update reads and filters#
The target introduces typed filters, explicit indexes, prepared queries, and query checkpoints. Verify:
- the fields and types accepted by each query target;
- which filter requires an index;
- that every required index is ready before switching readers;
- that the client follows the target pagination contract rather than deserializing a Ledger 2.x cursor shape;
- whether the workflow needs an HTTP live read or a gRPC consistency option.
Some Ledger 2.x reads have no direct spelling in Ledger 3.0. Most are replaced: prefix= and reference= by filter=, the per-account balances and volumes routes by the account read, and the account date fields by typed metadata, which your application writes. The /volumes point-in-time parameters are not available at all. Replaced and Removed Capabilities lists each one. Check a read path against that page before rewriting it: a workflow that depends on a capability Ledger 3.0 does not provide needs a design decision, not a new call site.
Do not compare complete source and target JSON payloads byte for byte. Normalize each workflow to the business fields it depends on.
Use Filters and Pagination and Indexes to build and verify each production read path.
Translate filters#
Ledger 2.x filters move into the filter query parameter, which takes a textual expression or a structured JSON one; see Filter and Paginate Results. Most Ledger 2.x JSON filters keep their shape. Check each one against these changes:
| Ledger 2.x | Ledger 3.0 |
|---|---|
JSON query body or query parameter | filter query parameter, textual or structured |
prefix=users: on accounts or volumes | filter=address ^= "users:" |
reference=order-1001 on transactions | filter={"$match":{"reference":"order-1001"}}, structured only |
startTime and endTime | startDate and endDate |
account on transactions | address, with the transaction-address index |
source, destination, reverted, and $exists on metadata | Unchanged. source and destination each need their own index |
inserted_at and reverted_at on transactions | insertedAt and revertedAt, structured only, each with its own index |
updated_at on transactions | No equivalent |
balance[USD/2] on accounts or volumes | No equivalent. Read volumes from the account list and compare balances in the client |
id and type on logs | logId, structured only. type has no equivalent |
Address segment wildcards: order::pending, users:... | address ^= "order:", then narrow with metadata. An empty segment or a trailing ... is not a wildcard |
$in | Textual in (...), or $or of $match conditions |
$like | No equivalent. Use an address prefix, or an exact reference match |
first_usage, insertion_date, updated_at on accounts | Not filterable. Use a typed datetime account metadata key with an index; see Account date fields |
| Metadata filters on any key | A declared metadata type and a ready metadata index per key |
| Metadata compared as strings, with no range operators | Values compared as the declared type. Numeric keys accept range operators |
Remove prefix= and reference= from every call. Ledger 3.0 ignores both parameters rather than rejecting them, so a Ledger 2.x call that still sends one returns the unfiltered list. This affects code that builds HTTP requests itself: the Ledger 3.0 API definition has no prefix or reference parameter, so an SDK generated from it has no field for either.
A trailing colon also changes meaning. In Ledger 2.x, users: matched exactly one more segment. In Ledger 3.0, address ^= "users:" and {"$match":{"address":"users:"}} match every address that starts with users:, at any depth, including users:alice:wallet. The closest Ledger 2.x spelling is users:....
Worked examples#
The examples below show one Ledger 2.x call and its Ledger 3.0 replacement. V2_URL is the base URL of your Ledger 2.x instance; LEDGER_URL, LEDGER_NAME, and CURL_AUTH are defined in Read Ledger Data. The data is the same on both sides: accounts under users: carry status, tier, and score metadata, and users:alice:wallet sits one level below users:alice.
Accounts under a prefix, by metadata#
The Ledger 2.x call returns active accounts exactly one segment below users::
curl --get "$V2_URL/v2/$LEDGER_NAME/accounts" \ --data-urlencode 'query={"$and":[{"$match":{"address":"users:"}},{"$match":{"metadata[status]":"active"}}]}'In Ledger 3.0, declare status as a string account metadata key and create the metadata:TARGET_TYPE_ACCOUNT:status index, then send either form:
curl --fail-with-body --silent --show-error --get \ "${CURL_AUTH[@]}" \ --data-urlencode 'filter=address ^= "users:" and metadata[status] == "active"' \ "$LEDGER_URL/v3/$LEDGER_NAME/accounts"Ledger 2.x returns users:alice and users:bob. Ledger 3.0 also returns users:alice:wallet, because the prefix covers every depth. Ledger 3.0 has no one-segment match: when depth matters, drop addresses that contain another : after the prefix in the client, or tag the accounts you want with metadata and filter on that.
Transactions involving an account, in a date range#
The Ledger 2.x call returns transactions that touch users:alice in March and April 2026:
curl --get "$V2_URL/v2/$LEDGER_NAME/transactions" \ --data-urlencode 'query={"$and":[{"$match":{"account":"users:alice"}},{"$gte":{"timestamp":"2026-03-01T00:00:00Z"}},{"$lt":{"timestamp":"2026-05-01T00:00:00Z"}}]}'In Ledger 3.0, account becomes address. Create the tx_builtin:TX_BUILTIN_INDEX_ADDRESS and tx_builtin:TX_BUILTIN_INDEX_TIMESTAMP indexes, then send either form:
curl --fail-with-body --silent --show-error --get \ "${CURL_AUTH[@]}" \ --data-urlencode 'filter=address == "users:alice" and timestamp >= "2026-03-01T00:00:00Z" and timestamp < "2026-05-01T00:00:00Z"' \ "$LEDGER_URL/v3/$LEDGER_NAME/transactions"Both versions return the same transactions. The date bounds can also move out of the filter into startDate=2026-03-01T00:00:00Z and endDate=2026-05-01T00:00:00Z, which the ledger combines with filter using AND.
A transaction by reference#
The Ledger 2.x call selects one transaction by its reference:
curl --get "$V2_URL/v2/$LEDGER_NAME/transactions" \ --data-urlencode 'query={"$match":{"reference":"order-1003"}}'Ledger 3.0 accepts the same structured condition. Create the tx_builtin:TX_BUILTIN_INDEX_REFERENCE index first. The textual form has no reference field, so keep this filter structured:
curl --fail-with-body --silent --show-error --get \ "${CURL_AUTH[@]}" \ --data-urlencode 'filter={"$match":{"reference":"order-1003"}}' \ "$LEDGER_URL/v3/$LEDGER_NAME/transactions"If the Ledger 2.x client sent reference=order-1003 instead, replace the parameter with this filter. Ledger 3.0 ignores reference= and returns every transaction.
Numeric metadata#
Ledger 2.x stored metadata as strings, so a numeric value was matched as text and range operators were rejected:
curl --get "$V2_URL/v2/$LEDGER_NAME/accounts" \ --data-urlencode 'query={"$match":{"metadata[score]":"15"}}'In Ledger 3.0, declare score as int64 and create the metadata:TARGET_TYPE_ACCOUNT:score index. Write the account metadata as a number. The textual form matches the number directly; the structured form expresses equality as a closed range:
curl --fail-with-body --silent --show-error --get \ "${CURL_AUTH[@]}" \ --data-urlencode 'filter=metadata[score] == 15' \ "$LEDGER_URL/v3/$LEDGER_NAME/accounts"Keeping the Ledger 2.x string, {"$match":{"metadata[score]":"15"}}, fails with 400 and FILTER_COMPILATION_ERROR, because the value does not match the declared type. Range filters such as metadata[score] >= 15 now work, which Ledger 2.x did not allow on metadata.
Update bulk handling#
The HTTP bulk route is /v3/{ledgerName}/bulk; Ledger 2.x _bulk paths do not carry over. The target returns per-element results and distinguishes business failures from infrastructure failures.
Choose the failure model explicitly:
- the default sequential mode commits successful elements in order and stops after the first failure;
continueOnFailure=truecontinues with later independent elements after a business failure;atomic=truesubmits the complete array as one Apply batch, so every element commits or none commits.
In atomic mode, send one batch-level Idempotency-Key header and preserve it with the exact array on an ambiguous retry. Per-element ik values identify requests only in sequential mode. Do not combine atomic=true with continueOnFailure=true: an atomic batch has no successful prefix to continue after.
The release/v3.0 HTTP handler supports atomic=true even though the current OpenAPI parameter description still says that it is not supported. Pin the application to the released server contract, inspect every per-element result, and test sequential failure, continuation, atomic rollback, and ambiguous whole-batch retries before enabling production bulk traffic.
See Bulk Transactions for the target request and result model.
Replace event integrations#
Ledger 2.x exporters and pipelines are not target client APIs. However, mirroring does not hide imported history from the target event system. Each supported Ledger 2.x change becomes an ordinary target log and produces the same standard event type as a target-native change, such as COMMITTED_TRANSACTION, REVERTED_TRANSACTION, SAVED_METADATA, or DELETED_METADATA.
A new sink replays imported Ledger 2.x history
A newly created target sink starts at cursor 0 and replays every supported event still present in the target global log, including the history imported from Ledger 2.x. Pointed at a live consumer, it re-fires the payouts, webhooks, and notifications that Ledger 2.x already delivered. The sink configuration exposes no start cursor that skips this replay.
Do not point a new target sink at a consumer that can immediately repeat production side effects. Stage the destination or consumer in quarantine first: accept and inspect replayed messages, but suppress notifications, payouts, webhooks, projections, and any other externally visible effect until the approved cutover boundary.
Inventory each consumer and define:
- the target event sink and event types;
- a target-delivery identity, normally the target cluster identity plus
logSequence, for at-least-once redelivery; - a business-effect identity that is stable across the Ledger 2.x pipeline and the target replay;
- the durable sink and consumer checkpoints used to prove that historical replay has drained;
- at-least-once delivery handling;
- the exact boundary after which target events may produce business effects;
- the source consumer stop point and the target consumer activation point.
The target logSequence identifies delivery inside the target cluster, but it does not identify an effect that the Ledger 2.x consumer already applied. Build the cross-version key from business data that survives mirroring—for example, a unique transaction reference when your domain guarantees one—and specify a key for every event type that causes an effect. If no stable cross-version identity exists for a workflow, keep its target effects disabled until you have reconciled and checkpointed the replay explicitly.
During rehearsal, let the target sink replay into quarantine, verify the standard target event shapes, and test the same mirrored business change against the Ledger 2.x receipt history. Record the point through which every replayed event is durably accepted without repeating an effect. This is a consumer-side migration checkpoint, not a sink start-cursor setting.
Data parity does not prove event-consumer compatibility. A successful rehearsal must prove both full replay handling and safe activation for the first post-boundary target event.
Use Configure an Event Sink and Consume and Recover to define the target delivery and recovery path.
Integration test gate#
Run a non-production client against a disposable normal ledger for writes and against the mirror for reads.
- Create a transaction with the target request shape.
- Retry it with the same idempotency key.
- Read it by ID and business reference.
- Read affected accounts and volumes.
- Revert a transaction and verify the compensating state.
- Save and delete account and transaction metadata.
- Traverse more than one page for each list workflow.
- Exercise every production filter after indexes are ready.
- Test expected 4xx conflicts and retryable infrastructure failures.
- Authenticate every application identity.
- Replay target events into quarantine without producing business effects.
- Deduplicate an imported event against the corresponding Ledger 2.x business effect.
- Record the replay checkpoint and prove that only post-boundary events can activate effects.
Do not generate a production client from a branch snapshot. Pin the SDK or generated client to the same released contract as the target deployed by Stack v4.
Continue with Create a Mirror.