@coinbase/cdp-cli 0.0.0 → 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/LICENSE +21 -0
- package/README.md +253 -0
- package/dist/index.js +492 -0
- package/dist/spec.json +1 -0
- package/dist/version.txt +1 -0
- package/package.json +36 -5
- package/scripts/postinstall.mjs +52 -0
- package/skills/cdp-accounts-create/SKILL.md +78 -0
- package/skills/cdp-accounts-import-export/SKILL.md +60 -0
- package/skills/cdp-accounts-send/SKILL.md +102 -0
- package/skills/cdp-accounts-sign/SKILL.md +65 -0
- package/skills/cdp-data/SKILL.md +78 -0
- package/skills/cdp-end-users/SKILL.md +60 -0
- package/skills/cdp-onramp/SKILL.md +60 -0
- package/skills/cdp-policies/SKILL.md +79 -0
- package/skills/cdp-setup/SKILL.md +90 -0
- package/skills/cdp-smart-accounts/SKILL.md +74 -0
- package/skills/cdp-solana/SKILL.md +79 -0
- package/skills/cdp-spend-permissions/SKILL.md +64 -0
- package/skills/cdp-swaps/SKILL.md +91 -0
- package/skills/cdp-x402/SKILL.md +124 -0
- package/index.js +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cdp-setup
|
|
3
|
+
description: Installs the CDP CLI and configures API key + wallet secret from the Coinbase Developer Portal. Verifies connectivity.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# cdp-setup
|
|
7
|
+
|
|
8
|
+
Set up the CDP CLI: install, configure API key and wallet secret, verify.
|
|
9
|
+
|
|
10
|
+
## Steps
|
|
11
|
+
|
|
12
|
+
1. **Check Node.js**: `node --version` — must be >= 22. If missing or too old, install from https://nodejs.org/en/download
|
|
13
|
+
|
|
14
|
+
**Warning (nvm/fnm users):** If you upgrade your default Node version, globally installed tools (e.g., Claude Code) will need to be reinstalled since each Node version has its own global packages. After upgrading, open a new terminal and reinstall any global tools you had on the previous version.
|
|
15
|
+
|
|
16
|
+
2. **Linux only — install keyring support** (prevents secrets from being stored in plaintext):
|
|
17
|
+
```
|
|
18
|
+
which secret-tool || sudo apt install -y libsecret-tools
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
3. **Check if `cdp` is installed**:
|
|
22
|
+
```
|
|
23
|
+
cdp --version
|
|
24
|
+
```
|
|
25
|
+
If not found:
|
|
26
|
+
```
|
|
27
|
+
npm i -g @coinbase/cdp-cli
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
4. **Create a CDP project and API key**:
|
|
31
|
+
> Go to https://portal.cdp.coinbase.com/projects/api-keys
|
|
32
|
+
> - Sign in (a project is auto-created on first sign-in).
|
|
33
|
+
> - Click **Create API Key** → **Download** the JSON key file.
|
|
34
|
+
> - Provide the path to the downloaded file.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
cdp env live --key-file <path>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
5. **Generate a wallet secret** (required for server wallet operations):
|
|
41
|
+
> Go to https://portal.cdp.coinbase.com/products/server-wallet/accounts
|
|
42
|
+
> - Click **Generate Wallet Secret** → **Download** the file.
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
cdp env live --wallet-secret-file <path>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
6. **Verify**:
|
|
49
|
+
```
|
|
50
|
+
cdp env
|
|
51
|
+
```
|
|
52
|
+
Assert: `live` appears with key ID and `(wallet)` indicator.
|
|
53
|
+
```
|
|
54
|
+
cdp evm accounts list
|
|
55
|
+
```
|
|
56
|
+
Assert: returns JSON (no auth error). May return `{"accounts":[]}`.
|
|
57
|
+
|
|
58
|
+
7. **Set up MCP server** (optional — gives your agent direct tool access to all CDP APIs):
|
|
59
|
+
|
|
60
|
+
The CDP CLI includes an MCP server (`cdp mcp`) that exposes every API endpoint as a tool.
|
|
61
|
+
|
|
62
|
+
**Claude Code:**
|
|
63
|
+
```
|
|
64
|
+
claude mcp add --scope user --transport stdio cdp -- cdp mcp
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Other agents** — add to your agent's MCP config (format varies by agent):
|
|
68
|
+
```json
|
|
69
|
+
{ "command": "cdp", "args": ["mcp"], "transport": "stdio" }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
8. **Install agent skills** (optional):
|
|
73
|
+
```
|
|
74
|
+
cdp skills add
|
|
75
|
+
```
|
|
76
|
+
If non-interactive, determine your agent's skills directory and pass it:
|
|
77
|
+
```
|
|
78
|
+
cdp skills add --dir <skills-directory>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
9. **Codex users**: If not running with `--sandbox danger-full-access` (full access mode), the default sandbox cannot access OS keychain secrets. Options:
|
|
82
|
+
- Prompt Codex to run `cdp` commands with "elevated access" (safest)
|
|
83
|
+
- Or use the `cdp mcp` server instead of direct CLI commands (MCP has expected keychain access in Codex)
|
|
84
|
+
|
|
85
|
+
10. **Troubleshooting**:
|
|
86
|
+
- "Must use a CDP Entity scoped API key" → need a v2 portal key, not legacy
|
|
87
|
+
- "Wallet authentication error" → wallet secret missing or incorrect
|
|
88
|
+
- "forbidden" → API key permissions issue
|
|
89
|
+
- After upgrading Node via nvm/fnm → open a new terminal, reinstall global tools that were on the old version
|
|
90
|
+
- Windows: `cdp` not found after `npm i -g` → add npm's global bin to PATH: `%APPDATA%\npm`
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cdp-smart-accounts
|
|
3
|
+
description: Creates ERC-4337 smart accounts, prepares and sends user operations with optional paymaster sponsorship. Requires an EOA owner.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# cdp-smart-accounts
|
|
7
|
+
|
|
8
|
+
Smart account lifecycle: create, user operations, paymaster.
|
|
9
|
+
|
|
10
|
+
## Create
|
|
11
|
+
|
|
12
|
+
1. Ensure a funded EOA owner exists (create via `/cdp-accounts-create` if needed).
|
|
13
|
+
2. ```
|
|
14
|
+
cdp evm smart-accounts create 'owners:=["<ownerAddress>"]' name=<name>
|
|
15
|
+
```
|
|
16
|
+
`owners` is a string array of addresses, NOT objects.
|
|
17
|
+
3. Verify:
|
|
18
|
+
```
|
|
19
|
+
cdp evm smart-accounts get <address>
|
|
20
|
+
cdp evm smart-accounts by-name <name>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Send via user operation
|
|
24
|
+
|
|
25
|
+
Smart accounts cannot use the encode→sign→send pipeline. Use user operations instead.
|
|
26
|
+
|
|
27
|
+
### Prepare and send (one step)
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
cdp evm smart-accounts user-operations prepare-and-send <smartAddress> \
|
|
31
|
+
network=base-sepolia \
|
|
32
|
+
'calls:=[{"to":"<recipient>","value":"10000000000000","data":"0x"}]'
|
|
33
|
+
```
|
|
34
|
+
Returns `.userOpHash`. Poll until complete:
|
|
35
|
+
```
|
|
36
|
+
cdp evm smart-accounts user-operations get <smartAddress> <userOpHash>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### With paymaster (gas sponsorship)
|
|
40
|
+
|
|
41
|
+
Add `paymasterUrl`:
|
|
42
|
+
```
|
|
43
|
+
cdp evm smart-accounts user-operations prepare-and-send <smartAddress> \
|
|
44
|
+
network=base-sepolia \
|
|
45
|
+
'calls:=[{"to":"<recipient>","value":"10000000000000","data":"0x"}]' \
|
|
46
|
+
paymasterUrl=https://paymaster.cdp.coinbase.com
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Note: paymaster covers gas only, not call value. For calls with non-zero value, fund the smart account directly first.
|
|
50
|
+
|
|
51
|
+
### Prepare then send (two steps)
|
|
52
|
+
|
|
53
|
+
1. Prepare:
|
|
54
|
+
```
|
|
55
|
+
cdp evm smart-accounts user-operations create <smartAddress> \
|
|
56
|
+
network=base-sepolia 'calls:=[{"to":"<to>","value":"0","data":"0x"}]'
|
|
57
|
+
```
|
|
58
|
+
2. Send:
|
|
59
|
+
```
|
|
60
|
+
cdp evm smart-accounts user-operations send <smartAddress> <userOpHash>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Verify
|
|
64
|
+
|
|
65
|
+
After user op completes, check recipient balance:
|
|
66
|
+
```
|
|
67
|
+
cdp evm token-balances get base-sepolia <recipient>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Notes
|
|
71
|
+
|
|
72
|
+
- Smart account addresses are deterministic from the owner address.
|
|
73
|
+
- Owner EOA must be funded on testnet for non-paymaster operations.
|
|
74
|
+
- `value` in calls is in wei as a string.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cdp-solana
|
|
3
|
+
description: Creates Solana accounts, transfers SOL and SPL tokens using tx-encode with v0 transactions. Handles faucet funding on devnet.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# cdp-solana
|
|
7
|
+
|
|
8
|
+
Solana account management and transfers.
|
|
9
|
+
|
|
10
|
+
## Create account
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
cdp solana accounts create name=<name>
|
|
14
|
+
```
|
|
15
|
+
Verify: `cdp solana accounts get <address>` and `cdp solana accounts by-name <name>`
|
|
16
|
+
|
|
17
|
+
## Fund (devnet)
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
cdp solana faucet address=<address> token=sol
|
|
21
|
+
```
|
|
22
|
+
Faucet tokens: sol, usdc. Faucet is rate-limited per address per 24h window. If limit hit, wait or fund from another account. Verify:
|
|
23
|
+
```
|
|
24
|
+
cdp solana token-balances get solana-devnet <address>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## SOL transfer
|
|
28
|
+
|
|
29
|
+
1. Encode (produces v0 transaction automatically):
|
|
30
|
+
```
|
|
31
|
+
cdp util tx-encode --network solana-devnet --to <recipient> --value <lamports> --from <sender>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. Decode and verify:
|
|
35
|
+
```
|
|
36
|
+
cdp util tx-decode <base64>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
3. Sign:
|
|
40
|
+
```
|
|
41
|
+
cdp solana accounts sign transaction <sender> transaction=<base64>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
4. Send:
|
|
45
|
+
```
|
|
46
|
+
cdp solana accounts send transaction network=solana-devnet transaction=<signedTransaction>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
5. Verify:
|
|
50
|
+
```
|
|
51
|
+
cdp solana token-balances get solana-devnet <sender>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
If `InsufficientFundsForRent` → new recipient accounts require at least 890000 lamports (0.00089 SOL) for rent-exemption. Send at least 1000000 lamports.
|
|
55
|
+
|
|
56
|
+
## SPL token transfer
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
cdp util tx-encode --network solana-devnet --to <recipient> --value <atomic_units> --from <sender> --token <mint_address>
|
|
60
|
+
```
|
|
61
|
+
Value is in atomic token units (e.g., 1000000 for 1 USDC with 6 decimals).
|
|
62
|
+
|
|
63
|
+
Then sign and send as above.
|
|
64
|
+
|
|
65
|
+
## Sign message
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
cdp solana accounts sign message <address> message="<message>"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Import / Export
|
|
72
|
+
|
|
73
|
+
See `/cdp-accounts-import-export` — works the same as EVM but uses base58 keys.
|
|
74
|
+
|
|
75
|
+
## Notes
|
|
76
|
+
|
|
77
|
+
- tx-encode auto-generates v0 transactions with recent blockhash.
|
|
78
|
+
- Solana faucet amounts: ~0.00125 SOL — enough for a few test transfers.
|
|
79
|
+
- SPL token transfers require the recipient to have an associated token account (created automatically by the transfer instruction if funded).
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cdp-spend-permissions
|
|
3
|
+
description: Sets up EIP-7702 delegation on an EOA and manages spend permissions — create, list, and revoke. Testnet delegations require gas.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# cdp-spend-permissions
|
|
7
|
+
|
|
8
|
+
EIP-7702 delegation + spend permission lifecycle.
|
|
9
|
+
|
|
10
|
+
## Preconditions
|
|
11
|
+
|
|
12
|
+
1. CLI configured → `/cdp-setup`
|
|
13
|
+
2. Funded EOA → `/cdp-accounts-create` (testnet delegations require gas; mainnet delegations are gas-sponsored by Coinbase)
|
|
14
|
+
3. Spender address → create a second account if needed
|
|
15
|
+
|
|
16
|
+
## Steps
|
|
17
|
+
|
|
18
|
+
### 1. EIP-7702 delegation
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
cdp evm accounts eip7702 delegation <address> network=base-sepolia 'enableSpendPermissions:=true'
|
|
22
|
+
```
|
|
23
|
+
If "Insufficient balance" → fund the EOA first.
|
|
24
|
+
|
|
25
|
+
Poll until COMPLETED:
|
|
26
|
+
```
|
|
27
|
+
cdp evm eip7702 delegation-operations <delegationOperationId>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. Create spend permission
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
cdp evm smart-accounts spend-permissions <address> \
|
|
34
|
+
network=base-sepolia token=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE \
|
|
35
|
+
allowance=1000000000000000 period=3600 \
|
|
36
|
+
start=<unix_now> end=<unix_now+86400> \
|
|
37
|
+
spender=<spenderAddress> paymasterUrl=https://paymaster.cdp.coinbase.com
|
|
38
|
+
```
|
|
39
|
+
Returns a user operation — poll until complete.
|
|
40
|
+
|
|
41
|
+
If "Smart Account with given address not found" → delegation may have failed or wrong address namespace.
|
|
42
|
+
|
|
43
|
+
### 3. List permissions
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
cdp evm smart-accounts spend-permissions list <address>
|
|
47
|
+
```
|
|
48
|
+
Extract `.spendPermissions[0].permissionHash`.
|
|
49
|
+
|
|
50
|
+
### 4. Revoke
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
cdp evm smart-accounts spend-permissions revoke <address> \
|
|
54
|
+
network=base-sepolia permissionHash=<hash>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Compatibility
|
|
58
|
+
|
|
59
|
+
| Account type | Supported |
|
|
60
|
+
|-------------|-----------|
|
|
61
|
+
| EVM EOA (delegated) | yes — requires EIP-7702 with enableSpendPermissions=true |
|
|
62
|
+
| Solana | no |
|
|
63
|
+
| Smart account (ERC-4337) | no — use EIP-7702 delegated EOA |
|
|
64
|
+
| End-user smart account | no — separate namespace |
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cdp-swaps
|
|
3
|
+
description: Executes EVM token swaps (ETH to ERC-20 or ERC-20 to ERC-20) with Permit2 approval flow. Mainnet only (base, ethereum, arbitrum, optimism, polygon).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# cdp-swaps
|
|
7
|
+
|
|
8
|
+
Token swap on EVM mainnet.
|
|
9
|
+
|
|
10
|
+
## Preconditions
|
|
11
|
+
|
|
12
|
+
1. CLI configured → `/cdp-setup`
|
|
13
|
+
2. Funded account on a mainnet network (base, ethereum, arbitrum, optimism, polygon).
|
|
14
|
+
3. Swaps are mainnet only — testnet networks are rejected.
|
|
15
|
+
|
|
16
|
+
## Steps
|
|
17
|
+
|
|
18
|
+
### 1. Get quote (read-only)
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
cdp evm swaps quote network==base toToken==0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 \
|
|
22
|
+
fromToken==0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE \
|
|
23
|
+
fromAmount==100000000000000 taker==<address>
|
|
24
|
+
```
|
|
25
|
+
Note: `==` for query params on GET.
|
|
26
|
+
|
|
27
|
+
### 2. Create swap
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
cdp evm swaps network=base toToken=<toToken> fromToken=<fromToken> \
|
|
31
|
+
fromAmount=<amount> taker=<address> signerAddress=<address>
|
|
32
|
+
```
|
|
33
|
+
`cdp evm swaps` IS the POST action (no `create` subcommand). Use `=` for body fields.
|
|
34
|
+
|
|
35
|
+
### 3. Handle Permit2 (ERC-20 source tokens only)
|
|
36
|
+
|
|
37
|
+
If response contains `.permit2.eip712`:
|
|
38
|
+
|
|
39
|
+
a. **One-time approval** — approve ERC-20 to Permit2 contract:
|
|
40
|
+
```
|
|
41
|
+
PERMIT2=0x000000000022d473030f116ddee9f6b43ac78ba3
|
|
42
|
+
APPROVE_DATA=$(cdp util abi-encode "approve(address,uint256)" $PERMIT2 115792089237316195423570985008687907853269984665640564039457584007913129639935)
|
|
43
|
+
```
|
|
44
|
+
Send via `/cdp-accounts-send` with `to=<fromToken_contract>`, `data=$APPROVE_DATA`, `value=0`.
|
|
45
|
+
|
|
46
|
+
b. **Sign Permit2 typed data**:
|
|
47
|
+
```
|
|
48
|
+
cdp evm accounts sign typed-data <address> \
|
|
49
|
+
primaryType=<permit2.eip712.primaryType> \
|
|
50
|
+
types:=<permit2.eip712.types> \
|
|
51
|
+
message:=<permit2.eip712.message> \
|
|
52
|
+
domain:=<permit2.eip712.domain>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
c. **Append signature to calldata**:
|
|
56
|
+
```
|
|
57
|
+
SIG_RAW="${signature:2}"
|
|
58
|
+
SIG_LEN="0000000000000000000000000000000000000000000000000000000000000041"
|
|
59
|
+
FULL_DATA="${swap.transaction.data}${SIG_LEN}${SIG_RAW}"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
If no `.permit2` (native ETH source) → use `swap.transaction.data` as-is.
|
|
63
|
+
|
|
64
|
+
### 4. Confirm with user
|
|
65
|
+
|
|
66
|
+
Show amount, estimated output, and network before proceeding.
|
|
67
|
+
|
|
68
|
+
### 5. Encode, sign, send
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
cdp util tx-encode --network <network> --to <swap.transaction.to> \
|
|
72
|
+
--data <FULL_DATA> --value <swap.transaction.value> --from <address> \
|
|
73
|
+
--gas-limit <swap.transaction.gas>
|
|
74
|
+
cdp evm accounts sign transaction <address> transaction=<tx>
|
|
75
|
+
cdp evm accounts send transaction <address> network=<network> transaction=<signedTransaction>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 6. Verify
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
cdp evm token-balances get <network> <address>
|
|
82
|
+
```
|
|
83
|
+
Assert: fromToken decreased, toToken increased.
|
|
84
|
+
|
|
85
|
+
## Compatibility
|
|
86
|
+
|
|
87
|
+
| Account type | Supported |
|
|
88
|
+
|-------------|-----------|
|
|
89
|
+
| EVM EOA | yes (mainnet only) |
|
|
90
|
+
| Smart account | no — taker must be EOA |
|
|
91
|
+
| Solana | no |
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cdp-x402
|
|
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
|
+
---
|
|
5
|
+
|
|
6
|
+
# cdp-x402
|
|
7
|
+
|
|
8
|
+
x402 HTTP payment protocol: supported schemes, bazaar discovery, payment construction and verification.
|
|
9
|
+
|
|
10
|
+
## Supported schemes
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
cdp x402 supported
|
|
14
|
+
```
|
|
15
|
+
Returns `.kinds` with available network/scheme combinations.
|
|
16
|
+
|
|
17
|
+
## Discover resources from bazaar
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
cdp api /x402/discovery/resources
|
|
21
|
+
```
|
|
22
|
+
Filter for target network from the response items.
|
|
23
|
+
|
|
24
|
+
## Verify payment (seller-side)
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
cdp x402 verify paymentPayload:=<json> paymentRequirements:=<json> x402Version:=2
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Settle payment (seller-side)
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
cdp x402 settle paymentPayload:=<json> paymentRequirements:=<json> x402Version:=2
|
|
34
|
+
```
|
|
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
|
+
|
|
109
|
+
## Notes
|
|
110
|
+
|
|
111
|
+
- `verify` and `settle` are for resource servers (sellers), not buyers.
|
|
112
|
+
- Buyer flow uses `cdp util x402` utils + resource signing commands.
|
|
113
|
+
- CDP facilitator: `https://api.cdp.coinbase.com/platform/v2/x402` (all networks, needs API key).
|
|
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>'`.
|
|
117
|
+
|
|
118
|
+
## Network support
|
|
119
|
+
|
|
120
|
+
| Network | Facilitator |
|
|
121
|
+
|---------|-------------|
|
|
122
|
+
| Base / Base Sepolia | CDP or x402.org (testnet) |
|
|
123
|
+
| Polygon | CDP |
|
|
124
|
+
| Solana / Solana Devnet | CDP or x402.org (testnet) |
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log("Temporary package");
|