-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathprogrammatic.ts
More file actions
44 lines (37 loc) · 1.12 KB
/
programmatic.ts
File metadata and controls
44 lines (37 loc) · 1.12 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
/**
* Example: Programmatic usage with createGraphQuery
*
* For scripts, bots, or simple integrations. No build step, no types.
*
* Prerequisites:
* npm install @graphprotocol/client-x402
*
* Usage:
* export X402_PRIVATE_KEY=0x...
* export X402_CHAIN=base-sepolia
* npx tsx programmatic.ts <endpoint> '<query>'
*
* Example:
* npx tsx programmatic.ts http://localhost:7700/api/x402/deployments/id/Qm... '{ indexers { id } }'
*/
import { createGraphQuery } from '@graphprotocol/client-x402'
const endpoint = process.argv[2]
const queryString = process.argv[3]
if (!process.env.X402_PRIVATE_KEY) {
console.error('Error: X402_PRIVATE_KEY is required')
process.exit(1)
}
if (!process.env.X402_CHAIN) {
console.error('Error: X402_CHAIN is required (base or base-sepolia)')
process.exit(1)
}
if (!endpoint || !queryString) {
console.error("Usage: npx tsx programmatic.ts <endpoint> '<query>'")
process.exit(1)
}
const query = createGraphQuery({
endpoint,
chain: process.env.X402_CHAIN as 'base' | 'base-sepolia',
})
const result = await query(queryString)
console.log(JSON.stringify(result.data, null, 2))