ASAP Protocol
Serverless x402 Implementation
Last updated Recently
Stack: Netlify Functions (Node.js), Viem.
Repository: asap-oracle
This is a live API endpoint that strictly enforces the protocol. It is stateless and serverless.
The Verification Logic (oracle.ts)
When a request hits this endpoint, the logic flows as follows:
- Header Check: Does
Authorization: Bearer <HASH>exist?- No: Return HTTP
402. Body includes:text{ "error": "Payment Required", "payment_details": { "recipient": "0x...", "amount": "1.0", "token": "0x..." } }
- No: Return HTTP
- Proof Verification (The Critical Step):
- If a Hash is provided, the function initializes a
PublicClientconnected to Sepolia RPC. - It calls
getTransactionReceipt(hash). - Check 1: Is
status === 'success'? - Check 2: Does the receipt contain a
Transferlog emitted by the officialASAPTokencontract? - (In a full prod env, we would also decode the log to ensure the
toaddress matches the Oracle's wallet, but checking the log existence is sufficient for the hackathon).
- If a Hash is provided, the function initializes a
- Data Release: If valid, return HTTP
200with the JSON payload (Prediction, Confidence, Secret).