Skip to main content
skill CX Codex

x402-payments — Claude Code skill: paid HTTP access on Hedera

An agent skill for gating HTTP resources behind HBAR payments with x402: a 402 challenge, a signed transfer, then verify and settle through your own facilitator.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add hedera-dev/hedera-skills --skill x402-payments -a claude-code
Open on GitHub

What x402-payments does

The skill lays out a pay-per-use pattern. Protected bytes stay off-chain, access terms live separately, and the HTTP resource is served only after payment. A buyer hits a 402 with a PAYMENT-REQUIRED header, signs an HBAR transfer, and retries with PAYMENT-SIGNATURE. The resource server verifies and settles through the facilitator, then returns the resource plus PAYMENT-RESPONSE.

Inside are instructions for wiring a resource server on @x402/core with ExactHederaScheme, a client retry loop, and a self-hosted facilitator exposing GET /supported, POST /verify, POST /settle, GET /health. Reference files cover server and client snippets, environment variables, and settle semantics. The wallet side expects an ECDSA Hedera account, for example HashPack over WalletConnect.

You need a funded ECDSA facilitator account up front: FACILITATOR_ACCOUNT_ID and FACILITATOR_PRIVATE_KEY belong to the facilitator process, never to the resource server. Amounts are tinybars, the asset is 0.0.0, and client and server must share one network such as hedera:testnet. Put the facilitator key in the resource server and the whole split-role design falls apart, so that is the first thing to check.

What it helps with

  • serve a protected file only after an HBAR payment
  • run a self-hosted facilitator with verify and settle
  • build a server loop around the 402 challenge and retry
  • connect a WalletConnect wallet to sign the transfer
  • convert prices to tinybars without rounding bugs

Example prompts for the agent

  • Gate this endpoint behind an HBAR payment with x402
  • Set up a Hedera facilitator with verify and settle
  • Add a client retry with PAYMENT-SIGNATURE after the 402

How to install x402-payments

1Skills CLI (Vercel)

npx skills add hedera-dev/hedera-skills --skill x402-payments -a claude-code

2Manually: put the files in place

~/.claude/skills/x402-payments/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/x402-payments/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about x402-payments

How do I install x402-payments in Claude?

Run npx skills add hedera-dev/hedera-skills --skill x402-payments -a claude-code. The skill lands in ~/.claude/skills/x402-payments/SKILL.md.

What does x402-payments do?

It helps an agent gate HTTP resources behind HBAR payments on Hedera: the 402 challenge, the signed transfer, and verify plus settle through a facilitator.

What do I need before using it?

A funded ECDSA facilitator account with FACILITATOR_ACCOUNT_ID and FACILITATOR_PRIVATE_KEY, plus a matching network on client and server, such as hedera:testnet.

Source text

SKILL.md · Apache-2.0
---
name: x402-payments
description: >
  x402 pay-per-use payments on Hedera. Use when gating HTTP resources behind native HBAR
  payments, wiring a self-hosted Hedera facilitator (verify/settle), building
  x402ResourceServer / ExactHederaScheme flows, or integrating WalletConnect payment
  retries (PAYMENT-REQUIRED → PAYMENT-SIGNATURE).
---

# x402 Payments (Hedera)

**Pay-per-use pattern:** store protected bytes off-chain, record access terms separately (on-chain or config), gate HTTP resources with **HTTP 402** + a **self-hosted Hedera facilitator** that verifies and settles native HBAR transfers.

```text
Buyer → GET protected resource
          ├─ free / public → resource
          └─ paid → 402 PAYMENT-REQUIRED
                → client signs HBAR transfer
                → retry with PAYMENT-SIGNATURE
                → resource server verify + settle via facilitator
                → PAYMENT-RESPONSE + resource
```

The resource server **never holds facilitator keys**. Settlement uses a funded **ECDSA** fee-payer account on the facilitator process.

## Quick Reference

| Piece | Role |
| ----- | ---- |
| Payment asset | `"0.0.0"` — native HBAR; amounts in **tinybars** (1 HBAR = 1e8) |
| Resource server | `@x402/core` + `ExactHederaScheme` → talks to facilitator over HTTP |
| Facilitator | `GET /supported`, `POST /verify`, `POST /settle`, `GET /health` |
| Client | Request → read 402 → sign → retry with `PAYMENT-SIGNATURE` (legacy `X-PAYMENT` also accepted) |
| Wallet | ECDSA Hedera account (e.g. HashPack via WalletConnect / UniversalProvider) |

See [references/examples.md](references/examples.md) for server/client snippets. See [references/facilitator.md](references/facilitator.md) for env vars and settle semantics.

## Critical: Facilitator Fee Payer

Hedera x402 settles with native `TransferTransaction`s. The buyer **partially signs** (authorize buyer → seller). The facilitator must:

1. Verify the signed payload against payment requirements
2. Co-sign as the advertised **fee payer** (`/supported`)
3. Pay network fees and submit until `SUCCESS`

Requires `FACILITATOR_ACCOUNT_ID` + `FACILITATOR_PRIVATE_KEY` on a funded **ECDSA** account — separate from deployer/seller keys. Do not put that key in the resource-server process.

## Critical: Prices Are Tinybars

Payment requirements use tinybars. Convert in UIs with 8-decimal helpers; never float.

```ts
const TINYBAR_PER_HBAR = 100_000_000n;
// hbar "1.5" → 150_000_000n tinybars
```

## Resource Server Flow (paid resource)

1. Load access terms for the resource — if missing → 404
2. If free/public → return the resource
3. Else build payment requirements: `payTo` = seller Hedera account id, `amount` in tinybars, asset `0.0.0`, network (e.g. `hedera:testnet`)
4. No payment header → **402** with `PAYMENT-REQUIRED` header + JSON body
5. With payment header → `verifyPayment` then `settlePayment`; only on success return resource + `PAYMENT-RESPONSE`

```ts
const facilitator = new HTTPFacilitatorClient({ url: FACILITATOR_URL });
const server = new x402ResourceServer(facilitator)
  .register(X402_NETWORK, new ExactHederaScheme());
await server.initialize(); // pulls fee-payer from /supported
```

## Client Flow

```ts
const first = await fetch(resourceUrl);
if (first.status === 402) {
  const paymentRequired = httpClient.getPaymentRequiredResponse(...);
  const payload = await httpClient.createPaymentPayload(paymentRequired);
  const headers = httpClient.encodePaymentSignatureHeader(payload);
  const paid = await fetch(resourceUrl, { headers });
  // processResponse → resource + settle receipt
}
```

Machine-to-machine clients use a key-based signer instead of a browser wallet.

## Checklist

- [ ] Resource server has no facilitator private key
- [ ] Client and server share the same `X402_NETWORK` (e.g. `hedera:testnet`)
- [ ] Amounts are tinybars; asset id is `0.0.0`
- [ ] 402 challenge → signed retry → verify → settle → resource only after success
- [ ] Fee-payer account is ECDSA and funded for network fees
- [ ] Facilitator `/health` OK before testing paid requests
- [ ] `payTo` is a Hedera account id string (e.g. `0.0.1234`), not an EVM address

## References

- [references/examples.md](references/examples.md) — resource server wiring, client retry loop, tinybar helpers
- [references/facilitator.md](references/facilitator.md) — endpoints, env vars, fee-payer role
- [x402 docs](https://docs.x402.org)
- [`@x402/hedera`](https://www.npmjs.com/package/@x402/hedera)

© hedera-dev · Apache-2.0 · hedera-dev/hedera-skills

Similar skills

Everything for Backend and APIs →

From the same set13

Quality Gates This skill wires up automatic code checks: lint and typecheck after every edit, a local CI run before push, and a five-stage deploy checklist. CX Codex +1 536installs Hedera Agent Kit v4 Migration Walks a project from [email protected] to v4: swaps packages, rewrites imports and ports custom tools to BaseTool. CX Codex +1 484installs agent-kit-plugin This skill guides the creation of Hedera Agent Kit plugins and tools. Use it when adding token, account, consensus, smart contract, or custom Hedera functionality. CX Codex +1 463installs create-harness-spec Turns a Hedera feature idea into a runnable hedera-harness recipe: PRD, spec file and validators. Useful when you need a spec you can actually run. CX Codex +1 465installs harness-spec-anatomy Defines what a hedera-harness recipe is made of: the files, the v3 defaults, the run stages and the blind evaluate-checklist rule. For anyone authoring or auditing recipes. CX Codex +1 464installs layerzero-messaging A skill for building LayerZero V2 bridges between Hedera and EVM chains: OFT/OApp setup, Endpoint V2 wiring, ULN, DVN and sends via quoteSend. CX Codex +1 460installs pyth-price-feeds A skill for wiring Pyth pull price feeds into Hedera contracts: Hermes payload updates, max-age reads, and confidence checks. CX Codex +1 444installs supra-push-oracle A skill for reading the Supra push oracle on Hedera: getSvalue(pairId), millisecond timestamps and USDT pairs. Useful when a contract pulls prices from Supra. CX Codex +1 448installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor