@coinbase/cdp-cli 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/version.txt CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinbase/cdp-cli",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "CLI for the Coinbase Developer Platform API",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: cdp-x402
3
- description: Explores x402 HTTP payment protocol — lists supported schemes, discovers resources from the bazaar, and verifies/settles payments.
3
+ description: Explores x402 HTTP payment protocol — lists supported schemes, discovers resources from the bazaar, constructs and signs payment payloads for EVM and Solana.
4
4
  ---
5
5
 
6
6
  # cdp-x402
7
7
 
8
- x402 HTTP payment protocol: supported schemes, bazaar discovery, payment verification.
8
+ x402 HTTP payment protocol: supported schemes, bazaar discovery, payment construction and verification.
9
9
 
10
10
  ## Supported schemes
11
11
 
@@ -21,13 +21,6 @@ cdp api /x402/discovery/resources
21
21
  ```
22
22
  Filter for target network from the response items.
23
23
 
24
- ## Test 402 response
25
-
26
- ```
27
- curl -s -o /dev/null -w "%{http_code}" <resourceUrl>
28
- ```
29
- Expect: 402 Payment Required.
30
-
31
24
  ## Verify payment (seller-side)
32
25
 
33
26
  ```
@@ -40,12 +33,87 @@ cdp x402 verify paymentPayload:=<json> paymentRequirements:=<json> x402Version:=
40
33
  cdp x402 settle paymentPayload:=<json> paymentRequirements:=<json> x402Version:=2
41
34
  ```
42
35
 
36
+ ## Buyer flow (pay for a 402 resource)
37
+
38
+ Uses consistent variable names across EVM and Solana: `addr`, `payload`, `sig`, `header`.
39
+
40
+ ### EVM flow
41
+
42
+ ```bash
43
+ # 1. Resolve account address
44
+ addr=$(cdp evm accounts by-name name=$ACCOUNT | jq -r .address)
45
+
46
+ # 2. Build EIP-712 typed data (client-side, no API call)
47
+ payload=$(cdp util x402 build --from $addr --payment-requirements "$REQ")
48
+
49
+ # 3. Sign typed data via CDP (extract fields from build output)
50
+ D=$(echo "$payload" | jq -c .domain)
51
+ T=$(echo "$payload" | jq -c .types)
52
+ P=$(echo "$payload" | jq -r .primaryType)
53
+ M=$(echo "$payload" | jq -c .message)
54
+ sig=$(cdp evm accounts sign typed-data $addr \
55
+ "domain:=$D" "types:=$T" "primaryType=$P" "message:=$M" | jq -r .signature)
56
+
57
+ # 4. Encode payment header (client-side)
58
+ header=$(cdp util x402 encode --payment-requirements "$REQ" \
59
+ --signature "$sig" --authorization "$M")
60
+
61
+ # 5. Make the paid request (send both headers for v1/v2 compatibility)
62
+ curl -H "X-PAYMENT: $header" -H "PAYMENT-SIGNATURE: $header" <resourceUrl>
63
+ ```
64
+
65
+ For `upto` scheme, override amount in step 2:
66
+ ```bash
67
+ payload=$(cdp util x402 build --from $addr --payment-requirements "$REQ" --amount 50000)
68
+ ```
69
+
70
+ ### Solana flow
71
+
72
+ ```bash
73
+ # 1. Resolve account address
74
+ addr=$(cdp solana accounts by-name name=$ACCOUNT | jq -r .address)
75
+
76
+ # 2. Build partially-signed transaction (client-side)
77
+ payload=$(cdp util x402 build --from $addr --payment-requirements "$REQ")
78
+
79
+ # 3. Sign transaction via CDP
80
+ sig=$(cdp solana accounts sign transaction $addr \
81
+ transaction="$(echo $payload | jq -r .transaction)" | jq -r .signedTransaction)
82
+
83
+ # 4. Encode payment header (client-side, no --authorization needed for Solana)
84
+ header=$(cdp util x402 encode --payment-requirements "$REQ" --signature "$sig")
85
+
86
+ # 5. Make the paid request
87
+ curl -H "X-PAYMENT: $header" -H "PAYMENT-SIGNATURE: $header" <resourceUrl>
88
+ ```
89
+
90
+ ### Decode a payment header
91
+
92
+ ```bash
93
+ cdp util x402 decode <base64-header>
94
+ ```
95
+
96
+ ## x402 utils reference
97
+
98
+ ```
99
+ cdp util x402 build --from <addr> --payment-requirements '<json>' [--amount N]
100
+ cdp util x402 encode --payment-requirements '<json>' --signature <sig> --authorization '<json>' [--x402-version N]
101
+ cdp util x402 decode <base64-header>
102
+ ```
103
+
104
+ - `build` detects chain from network field (eip155:* or v1 names like base, solana)
105
+ - `encode` defaults to v1 payload format. Use `--x402-version 2` for v2 servers (those using PAYMENT-REQUIRED header)
106
+ - `decode` is chain-agnostic
107
+ - All utils are client-side only (no API calls)
108
+
43
109
  ## Notes
44
110
 
45
111
  - `verify` and `settle` are for resource servers (sellers), not buyers.
46
- - Buyer flow is best handled by `@x402/fetch` or `@x402/axios` SDKs.
112
+ - Buyer flow uses `cdp util x402` utils + resource signing commands.
47
113
  - CDP facilitator: `https://api.cdp.coinbase.com/platform/v2/x402` (all networks, needs API key).
48
114
  - x402.org facilitator: testnet only, no signup.
115
+ - Some servers use `X-PAYMENT`, others use `PAYMENT-SIGNATURE` header. Send both for compatibility.
116
+ - POST endpoints (e.g. Nansen) require `-X POST -H "Content-Type: application/json" -d '<body>'`.
49
117
 
50
118
  ## Network support
51
119