Expand description
§OpenLibx402 Rocket
Rocket web framework integration for the X402 payment protocol.
This library provides guards and utilities to protect Rocket endpoints with payment requirements using the X402 protocol.
§Example
use rocket::{get, routes, State};
use openlibx402_rocket::{PaymentGuard, X402Config};
#[get("/premium-data")]
fn premium_data(_auth: PaymentGuard) -> &'static str {
"Premium content!"
}
#[rocket::main]
async fn main() {
let config = X402Config {
payment_address: "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU".to_string(),
token_mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".to_string(),
network: "solana-devnet".to_string(),
rpc_url: None,
auto_verify: true,
};
rocket::build()
.manage(config)
.mount("/", routes![premium_data])
.launch()
.await
.unwrap();
}Macros§
- payment_
required - Macro to create a payment-protected route handler
Structs§
- Payment
Guard - Request guard that enforces payment requirements
- Payment
Required Response - Response type for 402 Payment Required
- Payment
Requirement - Payment requirement configuration for a specific endpoint
- X402
Config - Global X402 configuration
Functions§
- create_
payment_ request - Create a payment request for an endpoint