FHE-encrypted x402 payments for OpenClaw agents. Use when the agent needs to make private on-chain payments, wrap/unwrap encrypted tokens, manage escrow jobs...
---
name: fhe-x402-payment
description: FHE-encrypted x402 payments for OpenClaw agents. Use when the agent needs to make private on-chain payments, wrap/unwrap encrypted tokens, manage escrow jobs, register agent identity, give reputation feedback, or delegate balance viewing. Runs on Ethereum Sepolia (default) or Mainnet with Zama fhEVM. Supports three wallet modes — local private key, DFNS MPC, and Ledger hardware wallet.
version: 1.0.0
metadata:
openclaw:
requires:
env:
- RPC_URL
anyBins:
- node
primaryEnv: USER_PRIVATE_KEY
emoji: "🔐"
homepage: "https://gitlab.com/bea7892046/fhex402"
---
# FHE x402 Payment Skill
Private, encrypted payments for autonomous agents on Ethereum using Zama's Fully Homomorphic Encryption (fhEVM). All payment amounts are encrypted on-chain — only the payer and payee can see them.
## Quick Start
Set a wallet and RPC, then run any command:
```bash
# Minimal setup (local dev)
export USER_PRIVATE_KEY=0x...
export RPC_URL=https://sepolia.infura.io/v3/YOUR_KEY
# Check wallet info
run info
# Wrap 10 USDC into encrypted cUSDC
run wrap --amount 10
# Send 1 encrypted cUSDC
run pay --to 0xRecipient --amount 1
# Check balance (with optional decrypt)
run balance
run balance --decrypt true
```
## Commands
### Token Operations
| Command | Description | Required Args |
|---------|-------------|---------------|
| `wrap` | Wrap USDC into encrypted cUSDC (ERC-7984) | `--amount` |
| `unwrap` | Initiate unwrap of cUSDC back to USDC (step 1 of 2) | `--amount` |
| `finalize-unwrap` | Complete unwrap via KMS decryption proof | `--handle` (recommended) or `--requestId --cleartextAmount --proof` (legacy) |
| `pay` | Send encrypted cUSDC via verifier relay | `--to --amount` |
| `balance` | Check USDC + cUSDC balances | Optional: `--decrypt true`, `--of 0xAddress` |
| `info` | Display wallet, network, and contract addresses | (none) |
### Escrow (Agentic Commerce Protocol — ERC-8183)
| Command | Description | Required Args |
|---------|-------------|---------------|
| `create-job` | Create an escrow job with provider + evaluator | `--provider --evaluator --expiry --description` Optional: `--hook` |
| `fund-job` | Encrypt budget + fund a job (3-step TX) | `--jobId --amount` |
| `complete-job` | Approve or reject a submitted job | `--jobId --action` (approve/reject) Optional: `--reason` |
### Identity & Reputation (ERC-8004)
| Command | Description | Required Args |
|---------|-------------|---------------|
| `register-agent` | Mint an agent identity NFT | `--uri` |
| `give-feedback` | Submit proof-linked reputation feedback | `--agentId --score --nonce` Optional: `--tag1 --tag2 --endpoint --feedbackURI --feedbackHash` |
### Delegation (FHE Viewing Keys)
| Command | Description | Required Args |
|---------|-------------|---------------|
| `grant-view` | Grant read access to your encrypted balance | `--delegate` Optional: `--hours --permanent --contract` |
| `revoke-view` | Revoke a delegate's view access | `--delegate` |
| `view-as` | Read another agent's balance via delegation | `--delegator` |
### Demo Orchestrators
| Command | Description | Required Args |
|---------|-------------|---------------|
| `research-and-visualize` | Chain 3 paid API calls (search + LLM + image) | `--query` |
| `review-and-rate` | Buy a code review + submit feedback | `--code` Optional: `--language --score` |
## Wallet Modes
Set `WALLET_MODE` to choose explicitly, or omit for auto-detection (DFNS > user key):
| Mode | Env Var | Best For |
|------|---------|----------|
| `user` | `USER_PRIVATE_KEY` | Local development, testing |
| `dfns` | `DFNS_WALLET_ID` + `DFNS_AUTH_TOKEN` + `DFNS_CREDENTIAL_ID` + (`DFNS_CREDENTIAL_PRIVATE_KEY` or `DFNS_PRIVATE_KEY_PATH`) | Unattended MPC agents |
| `ledger-bridge` | `LEDGER_BRIDGE_URL` + `LEDGER_BRIDGE_TOKEN` | Supervised hardware wallet |
## Environment Variables
### Required
| Variable | Description |
|----------|-------------|
| `RPC_URL` | Ethereum RPC endpoint (default: Sepolia public node) |
| `USER_PRIVATE_KEY` or `DFNS_WALLET_ID` | At least one wallet source |
### Optional
| Variable | Description |
|----------|-------------|
| `CHAIN` | `mainnet` or `sepolia` (auto-detected from RPC_URL) |
| `CUSDC_ADDRESS` | Override cUSDC token address |
| `VERIFIER_ADDRESS` | Override X402PaymentVerifier address |
| `ESCROW_ADDRESS` | Override AgenticCommerceProtocol address |
| `IDENTITY_ADDRESS` | Override AgentIdentityRegistry address |
| `REPUTATION_ADDRESS` | Override AgentReputationRegistry address |
All contract addresses auto-fill for Sepolia when `RPC_URL` points to chain ID 11155111.
## How It Works
1. **Encrypted Payments**: Uses Zama's fhEVM to encrypt USDC into cUSDC (ERC-7984). All transfers are confidential — amounts are FHE-encrypted on-chain.
2. **x402 Protocol**: Implements the HTTP 402 payment flow — servers return `402 Payment Required`, the agent encrypts and pays, then retries with a payment proof header.
3. **Escrow**: The AgenticCommerceProtocol (ERC-8183) holds encrypted budgets in escrow. Jobs flow through: create → setBudget → fund → submit → complete/reject.
4. **Identity**: Agents register as ERC-721 NFTs with EIP-712 wallet linking and on-chain metadata.
5. **Reputation**: Proof-of-payment feedback system prevents sybil attacks on agent ratings.
## Deployed Contracts (Sepolia)
| Contract | Address |
|----------|---------|
| cUSDC (ERC-7984) | `0x7c5BF43B851c1dff1a4feE8dB225b87f2C223639` |
| X402PaymentVerifier | `0xD46E80E1d37116B44c7Bfd845A110FCbB93d3E9F` |
| AgenticCommerceProtocol | `0xECD7a2382A5F0e3b6A7b76536e4CAE11215Cc695` |
| AgentIdentityRegistry | `0x36666464daa16442Fc1d901acfC9419f11407741` |
| AgentReputationRegistry | `0x1649d762Ee62f194D92B93510b8f10a501cE9fD5` |
## Output Format
All commands return JSON strings: `{ "ok": true, ... }` on success, `{ "ok": false, "error": "..." }` on failure. Commands never throw — errors are returned as JSON.
don't have the plugin yet? install it then click "run inline in claude" again.
use this skill when your agent needs to make private, encrypted payments on ethereum using fully homomorphic encryption (fhEVM), manage escrow jobs for agentic commerce, register identity as an nft, submit proof-linked reputation feedback, or delegate encrypted balance viewing to other agents. all payment amounts stay encrypted on-chain - only payer and payee see them. runs on ethereum sepolia (default) or mainnet with zama's fhEVM infrastructure. supports three wallet modes: local private key (dev), dfns mpc (unattended agents), and ledger hardware wallet (supervised). pick this skill for confidential agent-to-agent payments, private service payments via x402 http payment flow, or escrow-based agentic commerce workflows.
required environment variables:
RPC_URL: ethereum rpc endpoint (defaults to sepolia public node if not set). must resolve to either sepolia (chain id 11155111) or mainnet (chain id 1).USER_PRIVATE_KEY (wallet mode: user) OR DFNS_WALLET_ID + DFNS_AUTH_TOKEN + DFNS_CREDENTIAL_ID + DFNS_CREDENTIAL_PRIVATE_KEY or DFNS_PRIVATE_KEY_PATH (wallet mode: dfns) OR LEDGER_BRIDGE_URL + LEDGER_BRIDGE_TOKEN (wallet mode: ledger-bridge). at least one wallet source required.optional environment variables:
WALLET_MODE: explicitly set to user, dfns, or ledger-bridge. if omitted, auto-detects in order: dfns > user.CHAIN: mainnet or sepolia. auto-detected from rpc_url chain id if not provided.CUSDC_ADDRESS: override encrypted usdc (erc-7984) token address. defaults to sepolia 0x7c5BF43B851c1dff1a4feE8dB225b87f2C223639 or mainnet equivalent.VERIFIER_ADDRESS: override x402 payment verifier contract address.ESCROW_ADDRESS: override agenticcommerceprotocol (erc-8183) contract address.IDENTITY_ADDRESS: override agentidentityregistry (erc-721) contract address.REPUTATION_ADDRESS: override agentreputationregistry contract address.external connections:
node binaries required:
node (v16+): required to run all commands.step 1: wrap usdc into encrypted cusdc
amount (decimal string or number, e.g. "10" for 10 usdc), wallet credentials from env.run wrap --amount 10{ "ok": false, "error": "insufficient usdc balance" }.approve(cusdc_address, amount).step 2: check encrypted balance (optional decrypt)
--decrypt true flag (decryption requires fhEVM key material), optional --of 0xAddress to check another address (only works if delegation granted).run balance or run balance --decrypt true{ "usdc": "...", "cusdc": "..." } balances. if --decrypt true, decryption proof fetched from kms or local cache.step 3: send encrypted cusdc payment
--to 0xRecipient (eth address), --amount (decimal string).run pay --to 0xRecipient --amount 1{ "ok": false, "error": "verifier relay unavailable" }.step 4: initiate unwrap (cusdc to usdc)
--amount (decimal string).run unwrap --amount 5step 5: finalize unwrap (complete decryption proof)
--handle <handle> (recommended, auto-fetches proof) OR legacy args --requestId --cleartextAmount --proof.run finalize-unwrap --handle <handle> or run finalize-unwrap --requestId 123 --cleartextAmount 5 --proof 0x...step 6: create escrow job
--provider 0xProviderAddr, --evaluator 0xEvaluatorAddr, --expiry <unix timestamp>, --description "job details". optional: --hook 0xHookContract.run create-job --provider 0x... --evaluator 0x... --expiry 1704067200 --description "code review"step 7: fund job with encrypted budget
--jobId (uint256), --amount (decimal string). requires wrapped cusdc balance.run fund-job --jobId 1 --amount 50{ "ok": false, "failedStep": 2, "error": "out of gas" }.step 8: complete or reject job
--jobId, --action (approve or reject). optional: --reason "why".run complete-job --jobId 1 --action approve --reason "excellent work"step 9: register agent as erc-721 identity nft
--uri (ipfs or http uri pointing to agent metadata json).run register-agent --uri ipfs://QmXxxx...step 10: submit proof-linked reputation feedback
--agentId (nft token id), --score (0-100 integer), --nonce (to prevent replay). optional: --tag1 --tag2 (categorical tags), --endpoint (callback url), --feedbackURI (ipfs/http), --feedbackHash (keccak256).run give-feedback --agentId 5 --score 95 --nonce 1 --tag1 code-quality --tag2 responsiveness{ "ok": false, "error": "score must be 0-100" } without submitting tx.step 11: grant viewing permission to delegate
--delegate 0xDelegateAddr. optional: --hours <number> (time limit), --permanent true (override hours), --contract <address> (restrict to single contract, default all).