elizaos--eliza
426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
152 行
5.1 KiB
Markdown
152 行
5.1 KiB
Markdown
# @elizaos/plugin-x402
|
|
|
|
x402 micropayment middleware for elizaOS plugin HTTP routes.
|
|
|
|
This package lets Eliza agent plugins gate their HTTP routes behind the [x402 protocol](https://x402.org), requiring on-chain micropayments before serving responses. It handles HTTP 402 negotiation, payment verification (on-chain and facilitator-backed), and replay protection in one integration point.
|
|
|
|
## What it does
|
|
|
|
- **Declares payment requirements** via HTTP 402 responses with `accepts` arrays describing payment networks, token addresses, amounts, and resource URLs — compatible with x402scan indexing.
|
|
- **Verifies payments** using three strategies, tried in priority order:
|
|
1. Standard `X-Payment` / `PAYMENT-SIGNATURE` payloads (x402-fetch / CDP-style) verified and settled via a facilitator.
|
|
2. Direct on-chain proofs: Solana SPL token transfers (via `@solana/web3.js`), EVM ERC-20 transfers and EIP-712 authorizations (via `viem`).
|
|
3. Facilitator payment IDs via `X-Payment-Id` header.
|
|
- **Prevents replay attacks** using an atomic in-process guard plus a durable store backed by `runtime.setCache`/`getCache` (shared across processes when using the same DB).
|
|
- **Emits runtime events** on payment required (`PAYMENT_REQUIRED`) and verified (`PAYMENT_VERIFIED`).
|
|
|
|
## Supported networks and tokens
|
|
|
|
| Config name | Network | Token |
|
|
|-------------|---------|-------|
|
|
| `base_usdc` | Base (chain 8453) | USDC |
|
|
| `solana_usdc` | Solana | USDC |
|
|
| `polygon_usdc` | Polygon (chain 137) | USDC |
|
|
| `bsc_usdc` | BSC (chain 56) | USDC |
|
|
| `base_elizaos` | Base | elizaOS token |
|
|
| `solana_elizaos` | Solana | elizaOS token |
|
|
| `solana_degenai` | Solana | degenai |
|
|
|
|
## Enabling in a plugin
|
|
|
|
Install (it declares `@elizaos/core` as a peer dependency; in this monorepo that resolves via `workspace:*`):
|
|
|
|
```bash
|
|
bun add @elizaos/plugin-x402
|
|
```
|
|
|
|
Wrap your route array before returning them from your plugin:
|
|
|
|
```typescript
|
|
import { applyPaymentProtection } from '@elizaos/plugin-x402';
|
|
import type { Plugin, Route } from '@elizaos/core';
|
|
|
|
const routes: Route[] = applyPaymentProtection([
|
|
{
|
|
type: 'GET',
|
|
path: '/api/premium-data',
|
|
public: true,
|
|
x402: {
|
|
priceInCents: 10, // $0.10
|
|
paymentConfigs: ['base_usdc', 'solana_usdc'],
|
|
},
|
|
handler: async (req, res, runtime) => {
|
|
res.json({ result: 'premium content' });
|
|
},
|
|
},
|
|
]);
|
|
|
|
export const myPlugin: Plugin = { name: 'my-plugin', routes };
|
|
```
|
|
|
|
`applyPaymentProtection` validates config at call time and throws on misconfiguration so the agent fails fast at startup.
|
|
|
|
## Shorthand with character defaults
|
|
|
|
Set `x402: true` on a route to inherit price and payment configs from the agent character:
|
|
|
|
```typescript
|
|
// In character config:
|
|
character.settings.x402 = {
|
|
defaultPriceInCents: 10,
|
|
defaultPaymentConfigs: ['base_usdc', 'solana_usdc'],
|
|
};
|
|
|
|
// In route:
|
|
{ type: 'GET', path: '/api/resource', x402: true, handler: ... }
|
|
```
|
|
|
|
## Required environment variables
|
|
|
|
Set your payout wallet addresses. If unset, bundled example addresses are used (startup warns in dev, errors in production).
|
|
|
|
```
|
|
# Payout wallets (set the networks you want to accept)
|
|
SOLANA_PUBLIC_KEY=<your-solana-wallet>
|
|
BASE_PUBLIC_KEY=<your-base-evm-wallet>
|
|
POLYGON_PUBLIC_KEY=<your-polygon-evm-wallet>
|
|
BSC_PUBLIC_KEY=<your-bsc-evm-wallet>
|
|
```
|
|
|
|
## Optional environment variables
|
|
|
|
```
|
|
# Facilitator service (recommended for standard x402-fetch clients)
|
|
X402_FACILITATOR_URL=https://your-facilitator.example.com
|
|
|
|
# Override individual facilitator endpoints
|
|
X402_FACILITATOR_VERIFY_URL=https://your-facilitator.example.com/api/v1/x402/verify
|
|
X402_FACILITATOR_SETTLE_URL=https://your-facilitator.example.com/api/v1/x402/settle
|
|
|
|
# Public base URL for this server (used in resource URLs)
|
|
X402_BASE_URL=https://your-agent.example.com
|
|
|
|
# Development: skip all payment verification
|
|
X402_TEST_MODE=true
|
|
|
|
# Replay protection: use in-memory only (no DB persistence)
|
|
X402_REPLAY_DURABLE=0
|
|
|
|
# Custom RPC endpoints
|
|
SOLANA_RPC_URL=https://your-rpc.solana.com
|
|
BASE_RPC_URL=https://your-rpc.base.org
|
|
|
|
# Token prices for non-stablecoin configs (exact decimal string, dollars)
|
|
ELIZAOS_PRICE_USD=0.05
|
|
AI16Z_PRICE_USD=0.50
|
|
DEGENAI_PRICE_USD=0.01
|
|
|
|
# Debug logging
|
|
DEBUG_X402_PAYMENTS=true
|
|
```
|
|
|
|
## Custom payment configs
|
|
|
|
Register additional token/network combinations at plugin init time:
|
|
|
|
```typescript
|
|
import { registerX402Config } from '@elizaos/plugin-x402';
|
|
|
|
registerX402Config('mytoken_base', {
|
|
network: 'BASE',
|
|
assetNamespace: 'erc20',
|
|
assetReference: '0x<token-contract-address>',
|
|
paymentAddress: process.env.BASE_PUBLIC_KEY!,
|
|
symbol: 'MYTOKEN',
|
|
chainId: '8453',
|
|
});
|
|
```
|
|
|
|
Then reference `'mytoken_base'` in your route's `paymentConfigs` array.
|
|
|
|
## Payment headers
|
|
|
|
Clients send payment credentials in HTTP headers:
|
|
|
|
| Header | Purpose |
|
|
|--------|---------|
|
|
| `X-Payment` or `PAYMENT-SIGNATURE` | Standard x402 payload (base64 JSON with `x402Version`, `accepted`, `payload`) |
|
|
| `X-Payment-Proof` | Legacy proof: Solana tx sig, EVM tx hash, or colon-delimited format |
|
|
| `X-Payment-Id` | Facilitator-issued payment ID |
|
|
|
|
On success the response includes a `PAYMENT-RESPONSE` header from the facilitator and emits a `PAYMENT_VERIFIED` event on the agent runtime.
|