OrvynDocs

Developers

x402 on BNB Chain

Pay and get paid per request over HTTP 402, with Orvyn's facilitator or your own.

Orvyn implements x402 v2 on BNB Chain (eip155:56) with the exact scheme over Permit2 (extra.assetTransferMethod: "permit2"). BSC's USDT and USDC don't implement EIP-3009, so this is the path that works there.

How a payment works

  1. The client requests a resource and gets 402 with a PAYMENT-REQUIRED header (base64 JSON): accepted tokens, amount, payTo, timeout.
  2. The client signs a Permit2 PermitWitnessTransferFrom: spender = the x402 Permit2 proxy, witness = {to: payTo, validAfter}. It retries with the payload in PAYMENT-SIGNATURE.
  3. The server verifies it, serves the resource, and settles: the proxy pulls the funds straight from the payer to payTo. The result comes back in PAYMENT-RESPONSE.

The payer approves Permit2 for the token once; after that, every payment is only a signature.

Orvyn's facilitator

Orvyn runs a facilitator that verifies and settles payments, paying the gas itself. It never holds funds.

Endpoint
GET https://api.orvyn.cash/api/x402/supportedWhat it settles (exact/permit2 on eip155:56) and its gas wallets
POST https://api.orvyn.cash/api/x402/verify{ x402Version: 2, paymentPayload, paymentRequirements } → { isValid, invalidReason?, payer? }
POST https://api.orvyn.cash/api/x402/settleSame body → { success, transaction, network, payer, errorReason? }

verify and settle need an Orvyn API key (Authorization: Bearer <key>). It settles USDT and USDC up to a per-payment maximum, simulates every settlement first, and settles a retried payment only once.

Selling a resource (Rust)

The orvyn-core crate has a paywall that works with any HTTP framework: admit the request, serve it, then settle (work that fails isn't charged).

toml
[dependencies]
orvyn-core = { git = "https://github.com/OrvynOS/Core", tag = "v0.1.0" }
rust
use std::sync::Arc;
use alloy::primitives::U256;
use axum::{http::{HeaderMap, StatusCode}, response::{IntoResponse, Response}, Json};
use orvyn_core::x402::{self, Gate, Paywall, PriceOption, RemoteFacilitator};

fn paywall() -> Paywall {
    // Orvyn's facilitator (with your Orvyn API key), or x402::OrvynFacilitator with your own gas wallet.
    let facilitator = Arc::new(RemoteFacilitator::new("https://api.orvyn.cash/api/x402/", Some(std::env::var("ORVYN_API_KEY").unwrap())));
    let price = [PriceOption { asset: x402::BSC_USDT.into(), amount: U256::from(10u64).pow(U256::from(17)) }]; // 0.1 USDT
    Paywall::new("0xYourWallet", &price, facilitator).description("Daily market report")
}

async fn report(headers: HeaderMap) -> Response {
    let wall = paywall();
    let signature = headers.get(x402::HEADER_PAYMENT_SIGNATURE).and_then(|h| h.to_str().ok());
    let unpaid = |r: x402::PaymentRequired| (StatusCode::PAYMENT_REQUIRED, [(x402::HEADER_PAYMENT_REQUIRED, x402::encode_header(&r))], Json(r)).into_response();
    let admitted = match wall.admit("https://example.com/report", signature).await {
        Ok(Gate::Admitted(a)) => a,
        Ok(Gate::PaymentRequired(r)) => return unpaid(r),
        Err(e) => return (StatusCode::BAD_GATEWAY, e.message).into_response(),
    };
    let body = Json(serde_json::json!({ "report": "…", "payer": admitted.payer }));
    match wall.settle(admitted).await {
        Ok(Ok(settlement)) => ([(x402::HEADER_PAYMENT_RESPONSE, x402::encode_header(&settlement))], body).into_response(),
        Ok(Err(r)) => unpaid(r),
        Err(e) => (StatusCode::BAD_GATEWAY, e.message).into_response(),
    }
}

Add .payer_check(x402::agent_id_holders()) to sell only to Binance Agent ID holders.

Paying (Rust)

rust
use alloy::primitives::U256;
use alloy::signers::local::PrivateKeySigner;
use orvyn_core::wallets::LocalSigner;
use orvyn_core::x402::{self, SpendPolicy};

let key: PrivateKeySigner = std::env::var("PAYER_KEY")?.parse()?;
let first = reqwest::get("https://example.com/paid-resource").await?;
if first.status() == 402 {
    let required: x402::PaymentRequired = x402::decode_header(first.headers().get(x402::HEADER_PAYMENT_REQUIRED).and_then(|h| h.to_str().ok())).unwrap();
    let mut policy = SpendPolicy::default();
    policy.max_per_request.insert(x402::BSC_USDT.into(), U256::from(10u64).pow(U256::from(18))); // at most 1 USDT
    let offer = x402::choose_requirement(&required, &policy).expect("no acceptable offer");
    let payment = x402::sign_permit2_payment_raw(&LocalSigner(key), &offer, Some(required.resource)).await?;
    let paid = reqwest::Client::new().get("https://example.com/paid-resource").header(x402::HEADER_PAYMENT_SIGNATURE, x402::encode_header(&payment)).send().await?;
}

The policy picks the cheapest offer within your per-token cap and refuses anything else. The paying wallet approves Permit2 for the token once beforehand. Orvyn agents pay the same way through their wallet policy (x402::fetch_with_x402).

Note

Settlement uses the canonical x402 Permit2 proxy (0x402085c248EeA27D92E8b30b2C58ed07f9E20001) and Permit2 (0x000000000022D473030F116dDEE9F6B43aC78BA3). The facilitator checks the proxy is deployed on BNB Chain before settling.