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.
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 2000 satoshis. The middleware advertises payment requirements via HTTP 402 responses and validates incoming X-PAYMENT headers with a configured Facilitator.
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 to2000).
When X402_ENABLED=false, the server continues to operate without payment headers for local development or trusted deployments.
- 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).