-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.ts
More file actions
51 lines (43 loc) · 2.14 KB
/
demo.ts
File metadata and controls
51 lines (43 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* x402 Demo - Free endpoint (no payment needed)
*
* Tests connectivity to the Financial Oracles Gateway
* using the free /demo/quote endpoint.
*/
const GATEWAY = 'https://agents.krumpybot.com';
async function main() {
console.log('🔍 Testing x402 Financial Oracles Gateway...\n');
// 1. Free demo quote
console.log('1️⃣ Free demo quote (no payment)');
const demo = await fetch(`${GATEWAY}/demo/quote`);
const quote = await demo.json();
console.log(` AAPL: $${quote.price} (${quote.changePercent > 0 ? '+' : ''}${quote.changePercent}%)`);
console.log(` Demo: ${quote.demo}\n`);
// 2. Check pricing
console.log('2️⃣ Checking endpoint pricing');
const pricing = await fetch(`${GATEWAY}/pricing`);
const prices = await pricing.json();
const endpoints = Object.keys(prices.endpoints);
console.log(` ${endpoints.length} endpoints available`);
console.log(` Network: ${prices.network}`);
console.log(` Currency: ${prices.currency}`);
console.log(` Price range: $${Math.min(...Object.values(prices.endpoints) as number[])} - $${Math.max(...Object.values(prices.endpoints) as number[])}\n`);
// 3. Test 402 response
console.log('3️⃣ Testing x402 payment flow (no actual payment)');
const resp = await fetch(`${GATEWAY}/stocks/quote/MSFT`);
console.log(` Status: ${resp.status} (${resp.status === 402 ? '✅ Payment Required' : '❌ Unexpected'})`);
const x402 = await resp.json();
console.log(` Price: ${parseInt(x402.accepts[0].maxAmountRequired) / 1_000_000} USDC`);
console.log(` Pay to: ${x402.accepts[0].payTo}`);
console.log(` Network: ${x402.accepts[0].network}\n`);
// 4. Discovery
console.log('4️⃣ Discovery document');
const discovery = await fetch(`${GATEWAY}/.well-known/x402`);
const disc = await discovery.json();
console.log(` Version: ${disc.version}`);
console.log(` Resources: ${disc.resources.length}`);
console.log(` Has instructions: ${!!disc.instructions}\n`);
console.log('✅ Gateway is healthy and x402-compliant!');
console.log(` → To make paid requests, use @x402/fetch with a Base wallet`);
}
main().catch(console.error);