{"id":48294632,"url":"https://github.com/bitrouter/x402-kit","last_synced_at":"2026-04-04T23:30:01.813Z","repository":{"id":325443099,"uuid":"1100899700","full_name":"bitrouter/x402-kit","owner":"bitrouter","description":"A fully modular, framework-agnostic, easy-to-extend SDK for building complex X402 payment integrations.","archived":false,"fork":false,"pushed_at":"2026-03-19T20:53:02.000Z","size":607,"stargazers_count":51,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-03T06:59:35.438Z","etag":null,"topics":["rust","sdk","x402"],"latest_commit_sha":null,"homepage":"https://docs.rs/x402-kit","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitrouter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-20T23:07:03.000Z","updated_at":"2026-04-01T23:10:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bitrouter/x402-kit","commit_stats":null,"previous_names":["aimoverse/x402-kit","bitrouter/x402-kit"],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/bitrouter/x402-kit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitrouter%2Fx402-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitrouter%2Fx402-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitrouter%2Fx402-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitrouter%2Fx402-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitrouter","download_url":"https://codeload.github.com/bitrouter/x402-kit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitrouter%2Fx402-kit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31419078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","sdk","x402"],"created_at":"2026-04-04T23:30:01.300Z","updated_at":"2026-04-04T23:30:01.790Z","avatar_url":"https://github.com/bitrouter.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# X402 Kit\n\n[![Build status](https://github.com/AIMOverse/x402-kit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/AIMOverse/x402-kit/actions)\n[![Crates.io](https://img.shields.io/crates/v/x402-kit)](https://crates.io/crates/x402-kit)\n[![Documentation](https://docs.rs/x402-kit/badge.svg)](https://docs.rs/x402-kit)\n[![Twitter Follow](https://img.shields.io/twitter/follow/AiMoNetwork?style=social)](https://x.com/AiMoNetwork)\n[![Discord](https://img.shields.io/badge/Discord-Join%20AiMoNetwork-5865F2?style=flat\u0026logo=discord\u0026logoColor=white)](https://discord.gg/G3zVrZDa5C)\n\nA fully modular, framework-agnostic, easy-to-extend SDK for building complex X402 payment integrations.\n\n## 📦 Crates\n\n| Crate                                                   | Description                                                                |\n| ------------------------------------------------------- | -------------------------------------------------------------------------- |\n| [`x402-kit`](https://crates.io/crates/x402-kit)         | Main SDK with network definitions, payment schemes, and facilitator client |\n| [`x402-signer`](https://crates.io/crates/x402-signer)   | Buyer-side signing SDK with reqwest middleware for automatic x402 payments |\n| [`x402-core`](https://crates.io/crates/x402-core)       | Core traits, types, and transport mechanisms for the X402 protocol         |\n| [`x402-paywall`](https://crates.io/crates/x402-paywall) | Framework-agnostic HTTP paywall middleware                                 |\n\n## 📚 Developer Docs\n\nDocs are available at [docs.rs](https://docs.rs/x402-kit/latest/x402_kit/)\n\n## 💡 Core Pain Points Solved\n\nX402-kit is **not a facilitator** — it's a composable SDK for buyers (signers) and sellers (servers) to build custom business logic. Future support for modular facilitator components is planned.\n\n### Beyond Static Pricing and Payment Gateway Middlewares\n\nExisting X402 SDKs only support static prices per API route. X402-kit's fully modular architecture enables complex, dynamic pricing logic while maximizing code reuse.\n\n### Complete Modularity\n\nAll internal fields and methods are public by design. Compose and extend functionality freely without fighting the framework.\n\n### Layered Type Safety\n\n- **Transport Layer**: Uses generalized `String` types to prevent serialization failures and ensure service availability\n- **Network + Scheme Layer**: Leverages traits and generics for compile-time type checking without runtime overhead\n\n### Ship New Networks Without PRs\n\nImplement a new asset, network, or scheme entirely in your codebase and plug it into the SDK immediately—no upstream pull request or waiting period required thanks to trait-driven extension points.\n\nHowever, we still recommend contributing back any useful implementations to the main repository to help grow the ecosystem!\n\n### Production-Ready Design\n\nMinimize runtime errors through compile-time guarantees while maintaining the flexibility needed for real-world business logic.\n\n## 🧪 Usage Examples\n\n### Using `x402-paywall` with Axum\n\nThe `x402-paywall` crate (re-exported via `x402-kit`) provides a composable `PayWall` that handles the complete X402 payment flow. Run the example:\n\n```bash\nFACILITATOR_URL=https://your-facilitator.example \\\n  cargo run -p x402-kit --example axum_seller\n```\n\n#### Standard Payment Flow\n\nThe `handle_payment` method provides a complete flow: update accepts from facilitator, verify payment, run handler, and settle on success.\n\n```rust\nuse alloy::primitives::address;\nuse axum::{extract::{Request, State}, middleware::Next, response::{IntoResponse, Response}};\nuse url_macro::url;\nuse x402_kit::{\n    core::Resource,\n    facilitator_client::FacilitatorClient,\n    networks::evm::assets::UsdcBaseSepolia,\n    paywall::paywall::PayWall,\n    schemes::exact_evm::ExactEvm,\n};\n\nasync fn paywall_middleware(State(state): State\u003cAppState\u003e, req: Request, next: Next) -\u003e Response {\n    let paywall = PayWall::builder()\n        .facilitator(state.facilitator)\n        .accepts(\n            ExactEvm::builder()\n                .amount(1000)\n                .asset(UsdcBaseSepolia)\n                .pay_to(address!(\"0x3CB9B3bBfde8501f411bB69Ad3DC07908ED0dE20\"))\n                .build(),\n        )\n        .resource(\n            Resource::builder()\n                .url(url!(\"https://example.com/resource\"))\n                .description(\"X402 payment protected resource\")\n                .mime_type(\"application/json\")\n                .build(),\n        )\n        .build();\n\n    paywall\n        .handle_payment(req, |req| next.run(req))\n        .await\n        .unwrap_or_else(|err| err.into_response())\n}\n```\n\n#### Multiple Payment Options\n\nAccept payments on multiple networks (EVM and SVM):\n\n```rust\nuse x402_kit::{\n    networks::{evm::assets::UsdcBaseSepolia, svm::assets::UsdcSolanaDevnet},\n    schemes::{exact_evm::ExactEvm, exact_svm::ExactSvm},\n    transport::Accepts,\n};\n\nlet paywall = PayWall::builder()\n    .facilitator(facilitator)\n    .accepts(\n        Accepts::new()\n            .push(\n                ExactEvm::builder()\n                    .amount(1000)\n                    .asset(UsdcBaseSepolia)\n                    .pay_to(address!(\"0x3CB9B3bBfde8501f411bB69Ad3DC07908ED0dE20\"))\n                    .build(),\n            )\n            .push(\n                ExactSvm::builder()\n                    .amount(1000)\n                    .asset(UsdcSolanaDevnet)\n                    .pay_to(pubkey!(\"Ge3jkza5KRfXvaq3GELNLh6V1pjjdEKNpEdGXJgjjKUR\"))\n                    .build(),\n            ),\n    )\n    .resource(/* ... */)\n    .build();\n```\n\n#### Custom Payment Flow\n\nFor fine-grained control, use the step-by-step API:\n\n```rust\n// Skip verification, settle before running handler\nlet response = paywall\n    .process_request(req)?\n    .settle()\n    .await?\n    .run_handler(|req| next.run(req))\n    .await?\n    .response();\n```\n\n#### Access Payment State in Handlers\n\nThe `PayWall` injects `PaymentState` into request extensions:\n\n```rust\nuse axum::{Extension, Json};\nuse x402_kit::paywall::processor::PaymentState;\n\nasync fn handler(Extension(payment_state): Extension\u003cPaymentState\u003e) -\u003e Json\u003cValue\u003e {\n    Json(json!({\n        \"message\": \"Premium content accessed!\",\n        \"payer\": payment_state.verified.map(|v| v.payer),\n        \"transaction\": payment_state.settled.map(|s| s.transaction),\n    }))\n}\n```\n\n### Custom Facilitator Client\n\nCustomize request/response types for your facilitator.\n\n\u003e **Note:** The default facilitator client uses `Url::join(\"verify\")` etc. to construct endpoint URLs from the base URL. This means **trailing slashes matter**. For example, when using the Coinbase facilitator:\n\u003e\n\u003e ```bash\n\u003e export FACILITATOR_URL=https://www.x402.org/facilitator/\n\u003e ```\n\n```rust\nuse x402_kit::facilitator_client::{FacilitatorClient, IntoVerifyResponse, IntoSettleResponse};\n\n#[derive(Serialize, Deserialize)]\nstruct CustomSettleRequest { /* ... */ }\n\n#[derive(Deserialize)]\nstruct CustomSettleResponse { /* ... */ }\n\nimpl IntoSettleResponse for CustomSettleResponse {\n    fn into_settle_response(self) -\u003e SettleResult { /* ... */ }\n}\n\nlet facilitator = FacilitatorClient::from_url(facilitator_url)\n    .with_settle_request_type::\u003cCustomSettleRequest\u003e()\n    .with_settle_response_type::\u003cCustomSettleResponse\u003e();\n```\n\n### Buyer-Side Signing with `x402-signer`\n\nThe `x402-signer` crate provides a reqwest middleware that automatically handles the x402 payment flow: intercept HTTP 402 → sign payment → retry with payment header.\n\nYou need some testnet USDC on Solana devnet or Base Sepolia to run signer examples. You can get some at [Circle testnet faucet](https://faucet.circle.com/)\n\n#### EVM Client\n\n```bash\nEVM_PRIVATE_KEY=0x... RESOURCE_URL=http://localhost:3000/resource/standard \\\n  cargo run -p x402-signer --example evm_client\n```\n\n```rust\nuse alloy::signers::local::PrivateKeySigner;\nuse reqwest_middleware::ClientBuilder;\nuse x402_signer::{X402Client, evm::EvmPaymentSigner, middleware::X402PaymentMiddleware};\n\nlet wallet: PrivateKeySigner = \"0x...\".parse().unwrap();\nlet signer = EvmPaymentSigner::new(wallet);\nlet middleware = X402PaymentMiddleware::new(X402Client::new(signer));\n\nlet client = ClientBuilder::new(reqwest::Client::new())\n    .with(middleware)\n    .build();\n\n// Any 402 response is automatically signed and retried\nlet response = client.post(\"http://localhost:3000/resource/standard\").send().await?;\n```\n\n#### SVM Client\n\n```bash\nSOLANA_PRIVATE_KEY=\u003cbase58\u003e SOLANA_RPC_URL=https://api.devnet.solana.com \\\n  RESOURCE_URL=http://localhost:3000/resource/multi_payments \\\n  cargo run -p x402-signer --example svm_client\n```\n\n```rust\nuse solana_keypair::Keypair;\nuse solana_rpc_client::nonblocking::rpc_client::RpcClient;\nuse reqwest_middleware::ClientBuilder;\nuse x402_signer::{X402Client, svm::SvmPaymentSigner, middleware::X402PaymentMiddleware};\n\nlet keypair = Keypair::from_base58_string(\"\u003cbase58-private-key\u003e\");\nlet rpc = RpcClient::new(\"https://api.devnet.solana.com\".to_string());\nlet signer = SvmPaymentSigner::new(keypair, rpc);\nlet middleware = X402PaymentMiddleware::new(X402Client::new(signer));\n\nlet client = ClientBuilder::new(reqwest::Client::new())\n    .with(middleware)\n    .build();\n\nlet response = client.post(\"http://localhost:3000/resource/multi_payments\").send().await?;\n```\n\n## 🚀 Next Steps\n\n- More networks / assets / schemes\n- MCP / A2A transport support\n- Facilitator components support\n\n## 🤝 Contributing\n\nWe welcome all contributions to x402-kit! Here's how you can get involved:\n\n- ⭐ **Star** this repository\n- 🐛 **Open issues** to report bugs or suggest features\n- 🔧 **Submit PRs** to improve the codebase\n\nContributors will receive **priority access** and **rewards** at AIMO Network's Beta launch (coming soon)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitrouter%2Fx402-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitrouter%2Fx402-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitrouter%2Fx402-kit/lists"}