Skip to content

Commit 60bac13

Browse files
committed
chore: move x402 examples to examples folder
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
1 parent c48c3dd commit 60bac13

11 files changed

Lines changed: 1126 additions & 1086 deletions

File tree

File renamed without changes.
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Examples
1+
# x402 Examples
22

33
## Mode 1: CLI
44

@@ -7,7 +7,7 @@ See [`cli.sh`](./cli.sh) - query directly from the terminal.
77
```bash
88
export X402_PRIVATE_KEY=0x...
99
export X402_CHAIN=base-sepolia
10-
./cli.sh
10+
./cli.sh http://localhost:7700/api/x402/deployments/id/Qm... '{ indexers { id } }'
1111
```
1212

1313
## Mode 2: Programmatic
@@ -17,18 +17,16 @@ See [`programmatic.ts`](./programmatic.ts) - use in scripts without a build step
1717
```bash
1818
export X402_PRIVATE_KEY=0x...
1919
export X402_CHAIN=base-sepolia
20-
npx tsx programmatic.ts
20+
npx tsx programmatic.ts http://localhost:7700/api/x402/deployments/id/Qm... '{ indexers { id } }'
2121
```
2222

2323
## Mode 3: Typed SDK
2424

25-
See [`typed-sdk/`](./typed-sdk/) - full type safety with generated SDK.
25+
See [`index.ts`](./index.ts) + [`.graphclientrc.yml`](./.graphclientrc.yml) - full type safety with generated SDK.
2626

2727
```bash
28-
cd typed-sdk
2928
export X402_PRIVATE_KEY=0x...
3029
export X402_CHAIN=base-sepolia
3130
npx graphclient build
32-
rm .graphclient/package.json # Required: mesh generates broken ESM exports
3331
npx tsx index.ts
3432
```

examples/client-x402/cli.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Example: Query a paid subgraph endpoint using the CLI
3+
#
4+
# Prerequisites:
5+
# npm install -g @graphprotocol/client-x402
6+
#
7+
# Usage:
8+
# export X402_PRIVATE_KEY=0x...
9+
# export X402_CHAIN=base-sepolia
10+
# ./cli.sh <endpoint> '<query>'
11+
#
12+
# Example:
13+
# ./cli.sh http://localhost:7700/api/x402/deployments/id/Qm... '{ indexers { id } }'
14+
15+
set -e
16+
17+
if [ -z "$X402_PRIVATE_KEY" ]; then
18+
echo "Error: X402_PRIVATE_KEY is required"
19+
exit 1
20+
fi
21+
22+
if [ -z "$X402_CHAIN" ]; then
23+
echo "Error: X402_CHAIN is required (base or base-sepolia)"
24+
exit 1
25+
fi
26+
27+
if [ -z "$1" ] || [ -z "$2" ]; then
28+
echo "Usage: ./cli.sh <endpoint> '<query>'"
29+
exit 1
30+
fi
31+
32+
graphclient-x402 "$2" \
33+
--endpoint "$1" \
34+
--chain "$X402_CHAIN"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* export X402_PRIVATE_KEY=0x...
1111
* export X402_CHAIN=base-sepolia
1212
* npx graphclient build
13-
* rm .graphclient/package.json # Required: mesh generates broken ESM exports
1413
*
1514
* Then run this file:
1615
* npx tsx index.ts

examples/client-x402/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "client-x402-examples",
3+
"version": "1.0.0",
4+
"description": "See [`cli.sh`](./cli.sh) - query directly from the terminal.",
5+
"license": "MIT",
6+
"author": "Tomás Migone <tomas@edgeandnode.com>",
7+
"type": "module",
8+
"main": "index.js",
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"dependencies": {
13+
"@graphprotocol/client-x402": "^1.0.0"
14+
}
15+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Example: Programmatic usage with createGraphQuery
3+
*
4+
* For scripts, bots, or simple integrations. No build step, no types.
5+
*
6+
* Prerequisites:
7+
* npm install @graphprotocol/client-x402
8+
*
9+
* Usage:
10+
* export X402_PRIVATE_KEY=0x...
11+
* export X402_CHAIN=base-sepolia
12+
* npx tsx programmatic.ts <endpoint> '<query>'
13+
*
14+
* Example:
15+
* npx tsx programmatic.ts http://localhost:7700/api/x402/deployments/id/Qm... '{ indexers { id } }'
16+
*/
17+
18+
import { createGraphQuery } from '@graphprotocol/client-x402'
19+
20+
const endpoint = process.argv[2]
21+
const queryString = process.argv[3]
22+
23+
if (!process.env.X402_PRIVATE_KEY) {
24+
console.error('Error: X402_PRIVATE_KEY is required')
25+
process.exit(1)
26+
}
27+
28+
if (!process.env.X402_CHAIN) {
29+
console.error('Error: X402_CHAIN is required (base or base-sepolia)')
30+
process.exit(1)
31+
}
32+
33+
if (!endpoint || !queryString) {
34+
console.error("Usage: npx tsx programmatic.ts <endpoint> '<query>'")
35+
process.exit(1)
36+
}
37+
38+
const query = createGraphQuery({
39+
endpoint,
40+
chain: process.env.X402_CHAIN as 'base' | 'base-sepolia',
41+
})
42+
43+
const result = await query(queryString)
44+
console.log(JSON.stringify(result.data, null, 2))
File renamed without changes.

packages/x402/examples/cli.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/x402/examples/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/x402/examples/programmatic.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)