Expand description
§402fly Rocket
Rocket web framework integration for the 402fly payment protocol.
This library provides guards and utilities to protect Rocket endpoints with payment requirements using the 402fly protocol.
§Example
use rocket::{get, routes, State};
use fly402_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