Skip to content

agent-wallet send: return preimage in JSON output for L402 compatibility #92

@bolty-from-atl-bitlab

Description

@bolty-from-atl-bitlab

Summary

agent-wallet send returns only {"payment_hash":"..."} on success, but does not include the preimage (proof of payment). This makes it impossible for agents to complete L402 flows without parsing daemon logs.

Context

When an AI agent pays an L402-protected endpoint, the flow is:

  1. Request resource → get 402 with invoice + token
  2. Pay the invoice → get preimage
  3. Replay request with Authorization: L402 <token>:<preimage>

Step 2 fails because agent-wallet send doesn't return the preimage. The preimage is available internally — it appears in ~/.mdk-wallet/daemon.log:

Successfully sent payment of 37898000msat (fee 0 msat) from payment hash "d7ae..." with preimage "dc76..."
wait_for_payment_outcome saw event: PaymentSuccessful { payment_preimage: Some(dc76...) }

But the CLI output is just:

{"payment_hash":"d7ae9346c431c00e7e92f9210fb7b1e0cb89f3d52ec17414ec4f5a41fb50a8cf"}

Expected behavior

agent-wallet send should return the preimage on successful payment:

{
  "payment_hash": "d7ae...",
  "preimage": "dc76...",
  "amount_sats": 37898,
  "fee_msat": 0
}

This would also fix the amount_sats: 0 issue in payments.json for outbound payments.

Environment

  • @moneydevkit/agent-wallet@0.11.0-beta.1
  • macOS (arm64), Node v25.5.0

Additional context

Discovered while attempting to buy coffee from unhuman.coffee using the L402 protocol. The agent-wallet docs mention L402 compatibility ("pay the invoice and return the token and preimage to unlock the API") but the CLI doesn't surface the preimage needed to do this.

Workaround: parse ~/.mdk-wallet/daemon.log for the preimage, but this is fragile and not suitable for production agent workflows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions