Skip to content

examples: switchboard_x402_client — Rust ↔ Python interop demo#14

Merged
abhicris merged 2 commits into
kcolbchain:mainfrom
Pattermesh:patty/switchboard-example
May 23, 2026
Merged

examples: switchboard_x402_client — Rust ↔ Python interop demo#14
abhicris merged 2 commits into
kcolbchain:mainfrom
Pattermesh:patty/switchboard-example

Conversation

@Pattermesh
Copy link
Copy Markdown
Contributor

Adds `examples/switchboard_x402_client.rs` — an arka-based agent calling a paid endpoint served by Python switchboard's HTTP-402 middleware. Proves the wire format (`PaymentOffer` / `PaymentProof` JSON envelopes) is genuinely language-neutral: arka has no switchboard dependency, it just parses and emits the agreed shape.

What the example does

  • Creates a fresh arka `Agent` on Base
  • `GET endpoint` cold; expects `402 Payment Required` + `X-Payment-Required` header
  • Parses the `accepts[]` envelope (matches `switchboard.x402_middleware.PaymentOffer`)
  • Builds an `X-Payment-Proof` header (matches `switchboard.x402_middleware.PaymentProof`)
  • Retries with the proof; expects `200`

The tx-hash is stubbed for the demo (real settlement would go through arka's wallet or switchboard's `AgentEscrow` contract via alloy). The point is the wire — bytes leaving the Rust process round-trip through the Python middleware's `PaymentProof.from_header()` without loss.

Why this matters

  • The stack scene in switchboard's lab (web/agents-demo.html scene 09) names arka as a "consumer" of switchboard — this example backs that claim with runnable code.
  • When the spec evolves (PQ envelope kcolbchain/switchboard#33, receipt aggregation #43, private x402 #44), this example is the canary that catches wire drift between the Rust and Python sides.
  • The planned adversarial conformance harness (#45) will eventually run this as a cross-language fixture.

Tests

`cargo check --example switchboard_x402_client` passes clean (no warnings). The example is run-only (needs the Python middleware up); it's not part of the default test suite.

Other changes

  • README.md examples table updated to include `switchboard_x402_client`

cc @abhicris

🤖 Generated with Claude Code

Adds examples/switchboard_x402_client.rs — an arka-based agent
calling a paid endpoint served by Python switchboard's HTTP-402
middleware. Proves the wire format (PaymentOffer / PaymentProof JSON
envelopes) is genuinely language-neutral: arka has no switchboard
dependency, just parses and emits the agreed shape.

What the example does:
- Creates a fresh arka Agent on Base
- GET endpoint cold; expects 402 + X-Payment-Required header
- Parses the accepts[] envelope (matches switchboard.x402_middleware.PaymentOffer)
- Builds an X-Payment-Proof header (matches switchboard.x402_middleware.PaymentProof)
- Retries with the proof; expects 200

The tx-hash is stubbed for the demo (real settlement would go through
arka's wallet or switchboard's AgentEscrow contract via alloy). The
point is the wire — bytes leaving this Rust process round-trip
through the Python middleware's PaymentProof.from_header() without
loss.

Why this matters
- The stack scene in switchboard's lab (web/agents-demo.html scene
  09) names arka as a "consumer" — this example backs that claim with
  runnable code.
- When the spec evolves (PQ envelope #33, receipt aggregation #43,
  privacy-preserving x402 #44), this example is the canary that
  catches wire drift between the Rust and Python sides. Adversarial
  conformance harness #45 will eventually run this as a fixture.

Also updates examples table in README.md.

Cross-references
- switchboard repo:        https://github.com/kcolbchain/switchboard
- switchboard live lab:    https://kcolbchain.github.io/switchboard/agents-demo.html
- switchboard PR for PQ:   kcolbchain/switchboard#33

cargo check passes clean (no warnings).
@abhicris
Copy link
Copy Markdown
Contributor

Welcome to kcolbchain, @Pattermesh — glad you're here. 🌱

Here's what happens from this PR:

  1. Our automated review looks for obvious issues (tests, secrets, size) within a couple of hours.
  2. If it's clean and CI passes, we merge without back-and-forth.
  3. If we need changes, we'll leave a specific comment — not a generic nit. Push another commit and we re-review.

While you wait:

  • Run the repo's tests locally (see the repo README.md).
  • Keep the PR scoped to one concern — bigger PRs land slower.
  • Don't commit tokens or .env contents.

What happens after your first merge

Thanks for writing the code. We're building this to last.

@abhicris
Copy link
Copy Markdown
Contributor

🤖 Audit verdict: safe

Example file demonstrating HTTP-402 payment interop with proper error handling, no hardcoded secrets, ephemeral wallet generation, and mocked transaction for demo purposes only.

Audited by the kcolbchain PR pipeline. See pipeline docs.

@abhicris abhicris merged commit e9cb87c into kcolbchain:main May 23, 2026
1 check passed
@abhicris
Copy link
Copy Markdown
Contributor

Merged — thank you, @Pattermesh. Your first kcolbchain contribution is in. 🎉

A few things that unlocked with this merge:

If you want to stay in the loop on what we're shipping: https://kcolbchain.com/ROADMAP.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants