Skip to main content

Crate openlibx402_rocket

Crate openlibx402_rocket 

Source
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§

PaymentGuard
Request guard that enforces payment requirements
PaymentRequiredResponse
Response type for 402 Payment Required
PaymentRequirement
Payment requirement configuration for a specific endpoint
X402Config
Global X402 configuration

Functions§

create_payment_request
Create a payment request for an endpoint