Skip to main content
examples/headless-close.ts is the reference implementation for an integration. It closes a throwaway testnet account end to end with no browser or web UI. It funds two accounts through Friendbot, adds a data entry, then runs getAccount, closePlan, closeTransactions, and submit through runClose, signing with an in-process keypair. examples/exchange-close.ts is the same close to an exchange deposit address, through the shared intermediary. See Close to an exchange. examples/plan-only.ts is its read-only counterpart: it rehearses the close of any account, mainnet included, without holding a key or building a transaction. See Rehearse a mainnet account. All three run every night in CI against testnet, so a change that breaks them against the API is caught the next morning.

The part to copy

Before signing, the example checks every transaction with @lumenwipe/verify against its own inputs and the account read, in examples/verify.ts. It rejects any operation the web verifier does not accept. This is the pattern to follow. See Verification. The example’s verifier covers only what a simple account needs: data entries, empty trustlines, and open offers. A production integration needs a wider check.

Signing weight

The example does not assume its key is enough. For each transaction it takes the strictest threshold its operations need (high for the merge, medium for removing a data entry, trustline or offer) from the signers and thresholds the round was built from, and reports the weight its key actually carries. When that falls short, runClose stops with InsufficientSignatureWeightError before submitting, and the error’s pending holds the partially signed envelope: sign it with another key and pass it back as runClose(deps, error.pending). See runClose.

Errors

Nothing is swallowed. Waiting for a new account retries only what waiting can fix: an account the network does not show yet, a 429 or 5xx (honouring Retry-After), a timeout or a connection that never got a response. A rejected key or request fails at once. Every failure exits with code 1 and prints the error’s typed fields, never only its message:
When retries run out, the last error is printed as the cause. A promise rejection nothing awaited fails the run the same way.

Recording what arrived

An integration that keeps its own record of a close reads the XLM received from the ledger, never from the plan. Collect the hashes runClose confirmed through onConfirmed, then call closeDelivered:
Amounts are in stroops, as strings. Only a merge into the destination, or the relay account’s forward of a merged balance for an exchange close, counts; a path payment, any other payment and any asset other than XLM do not. A transaction that is unknown, failed or delivered nothing this way is an unavailable entry with its reason, and totalStroops is set only when every entry is delivered, so a missing amount never reads as zero. See the API reference.

Run it

Create an API key at lumenwipe.com/api-keys, then, from the repository root:
LUMENWIPE_API_URL overrides the default https://api.lumenwipe.com. The example runs on testnet only.

Close to an exchange

Exchanges do not accept an account merge. A close to one is a single transaction with two operations: the account merges into the shared intermediary, and the intermediary forwards the balance in XLM to the exchange address with the deposit memo. The API co-signs the forward with the intermediary’s key (mediatorSign). The example adds three things to the headless close:
  • The registry decides, not the API. Whether the destination needs the intermediary comes from requiresMediator(destination, network) in @lumenwipe/verify, which reads the exchange registry bundled in that package for that network. Before anything is built, the example also calls mediatorCheck and stops with MediatorUnavailableError (with its available and registryFresh fields printed) when the API cannot co-sign. Otherwise the cleanup round would land and the merge would then be refused.
  • The memo is an input. The deposit memo goes to closeTransactions and to the verifier, which refuses a transaction carrying any other memo, a forward to any address but the one typed, or a forward smaller than the balance read.
  • The co-signature may only add a signature. In runClose’s prepare step, the example asks for the co-signature only on the merge of a close to a listed exchange, decided from the destination it typed and the decoded transaction. It refuses the returned envelope when its hash differs from the one it signed, when it dropped a signature, or when it carries no new one. Nothing is submitted in those cases.
When the close confirms, it reads what reached the exchange with closeDelivered: only the intermediary’s forward counts. These are the checks listed under Mediated closes. The destination is the Coinbase deposit address from the bundled registry, used on testnet, where the XLM is worthless and nobody here holds its key. A forward is a payment, which needs an existing account, so the example creates the address with Friendbot when a testnet reset has removed it. The API needs an intermediary key for the network. A self-hosted API takes a throwaway testnet one:
Then, from the repository root:
The example runs on testnet only and refuses any other network. Never use a mainnet intermediary key for it.

Rehearse a mainnet account

Before the first real close, run the plan-only example against the account. It calls only getAccount and closePlan: no key is read, and no transaction is requested, built, signed or submitted.
It prints the account, the plan, the decisions the close will need and every blocker. The exit code is 0 when nothing blocks the close, 2 when something does, and 1 on an error. LUMENWIPE_NETWORK defaults to testnet. CI only ever runs it against testnet; pointing it at mainnet is for your own rehearsal.