Errors
solana-pay-kit's error type and the boot-time safety rails that reject a bad config before the server serves traffic.
PayKit::new returns Result<PayKit, PayKitError>, so a bad configuration fails at startup rather than at request time. Per-request payment failures are turned into the 402 response by the gate — your handler only runs once a payment verifies.
PayKitError
The error carries which protocol handler rejected the config:
| Variant | Meaning |
|---|---|
PayKitError::Mpp(String) | The MPP charge handler rejected the config. |
PayKitError::X402(String) | The x402 handler rejected the config. |
let pay = match PayKit::new(config) {
Ok(pay) => pay,
Err(PayKitError::Mpp(msg)) => panic!("MPP config rejected: {msg}"),
Err(PayKitError::X402(msg)) => panic!("x402 config rejected: {msg}"),
};Boot-time safety rails
PayKit::new validates the config up front:
- A
challenge_binding_secretshorter than 32 bytes (or empty) is rejected — generate one withopenssl rand -base64 32. When it isNone, the MPP layer readsMPP_SECRET_KEY. - An unknown
networkslug is rejected; the canonical slugs aremainnet,devnet, andlocalnet.
Signers
Load the operator key that sponsors network fees and signs upto/batch settlement — local keypairs or remote backends — via Solana Keychain.
Go SDK
Gate any HTTP route for stablecoin payments with the pay-kit Go module — one paykit umbrella, net/http middleware that advertises both MPP and x402.