mirror of
https://github.com/Permissionless-Software-Foundation/psf-bch-api-base.git
synced 2026-09-21 16:52:00 -07:00
fed4b2da5984262a4697f2b10102ea4076c66025
psf-bch-api
This is a REST API for communicating with Bitcoin Cash infrastructure. It replaces bch-api, and it implements x402-bch protocol to handle payments to access the API.
License
x402-bch Payments
All REST endpoints exposed under the /v6 prefix are protected by the x402-bch-express middleware. Each API call requires a BCH payment authorization for 200 satoshis. The middleware advertises payment requirements via HTTP 402 responses and validates incoming X-PAYMENT headers with a configured Facilitator.
Configuration
Environment variables control the payment flow:
X402_ENABLED— set tofalse(case-insensitive) to disable the middleware. Defaults to enabled.SERVER_BCH_ADDRESS— BCH cash address that receives funding transactions. Defaults tobitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d.FACILITATOR_URL— Root URL of the facilitator service (e.g.,http://localhost:4345/facilitator).X402_PRICE_SAT— Optional; override the satoshi price per call (defaults to200).
When X402_ENABLED=false, the server continues to operate without payment headers for local development or trusted deployments.
Manual Verification
- Start or point to an
x402-bchfacilitator service (the example facilitator listens athttp://localhost:4345/facilitator). - Run the API server with the default configuration:
npm start. - Call a protected endpoint without an
X-PAYMENTheader, e.g.curl -i http://localhost:5942/v6/full-node/control/getNetworkInfo. The server will respond with HTTP402and include payment requirements. - Restart the server with
X402_ENABLED=false npm startto confirm that the same request now bypasses the middleware (useful for local development without payments).
Languages
JavaScript
99.2%
Dockerfile
0.7%