Skip to content

Commit 3874b3b

Browse files
committed
x402 SDK v0.4.0 - Full v2 upgrade with CAIP-2 networks
1 parent 8497bd7 commit 3874b3b

43 files changed

Lines changed: 12805 additions & 6539 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ on:
77
branches: [main]
88

99
jobs:
10-
test:
10+
typescript:
11+
name: TypeScript SDK
1112
runs-on: ubuntu-latest
1213

1314
defaults:
1415
run:
15-
working-directory: ./sdk
16+
working-directory: ./sdk-typescript
1617

1718
steps:
1819
- name: Checkout repository
@@ -23,10 +24,35 @@ jobs:
2324
with:
2425
node-version: '20'
2526
cache: 'npm'
26-
cache-dependency-path: sdk/package-lock.json
27+
cache-dependency-path: sdk-typescript/package-lock.json
2728

2829
- name: Install dependencies
2930
run: npm ci
3031

3132
- name: Run tests
3233
run: npm test
34+
35+
python:
36+
name: Python SDK
37+
runs-on: ubuntu-latest
38+
39+
defaults:
40+
run:
41+
working-directory: ./sdk-python
42+
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
47+
- name: Setup Python
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version: '3.12'
51+
cache: 'pip'
52+
cache-dependency-path: sdk-python/pyproject.toml
53+
54+
- name: Install dependencies
55+
run: pip install -e ".[dev]"
56+
57+
- name: Run tests
58+
run: pytest

README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Primer x402
22

3-
[![Tests](https://github.com/Primer-Systems/x402/actions/workflows/test.yml/badge.svg)](https://github.com/Primer-Systems/x402-private/actions/workflows/test.yml)
3+
[![Tests](https://github.com/PrimerSystems/x402/actions/workflows/test.yml/badge.svg)](https://github.com/PrimerSystems/x402/actions/workflows/test.yml)
44

5-
Implementation of the [x402 payment protocol](https://x402.org) for HTTP 402 payments on Base.
5+
Implementation of the [x402 payment protocol](https://x402.org) for HTTP 402 payments.
66

77
## Components
88

9-
- **sdk/** - JavaScript SDK for payers and payees
9+
- **sdk-typescript/** - JavaScript/TypeScript SDK for payers and payees
10+
- **sdk-python/** - Python SDK for payers and payees
1011
- **tools/** - CLI tools for testing and token approval
1112
- **Contracts/** - *Prism* smart contract for ERC-20 settlements
1213

@@ -17,7 +18,8 @@ Implementation of the [x402 payment protocol](https://x402.org) for HTTP 402 pay
1718
```javascript
1819
const { createSigner, x402Fetch } = require('@primersystems/x402');
1920

20-
const signer = await createSigner('base', process.env.PRIVATE_KEY);
21+
// Use CAIP-2 network format (eip155:chainId)
22+
const signer = await createSigner('eip155:8453', process.env.PRIVATE_KEY);
2123
const fetch402 = x402Fetch(fetch, signer, { maxAmount: '1.00' });
2224

2325
const response = await fetch402('https://example.com/api/paywall');
@@ -32,17 +34,23 @@ app.use(x402Express('0xYourAddress', {
3234
'/api/paywall': {
3335
amount: '0.01',
3436
asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
35-
network: 'base'
37+
network: 'eip155:8453' // CAIP-2 format
3638
}
3739
}));
3840
```
3941

4042
## Supported Networks
4143

42-
| Network | Chain ID |
43-
|---------|----------|
44-
| Base | 8453 |
45-
| Base Sepolia | 84532 |
44+
Networks use [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md) identifiers.
45+
46+
| Network (CAIP-2) | Chain ID | Name | Default Facilitator |
47+
|------------------|----------|------|---------------------|
48+
| eip155:8453 | 8453 | Base | ✓ Primer |
49+
| eip155:84532 | 84532 | Base Sepolia | ✓ Primer |
50+
| eip155:1 | 1 | Ethereum | Custom required |
51+
| eip155:42161 | 42161 | Arbitrum | Custom required |
52+
| eip155:10 | 10 | Optimism | Custom required |
53+
| eip155:137 | 137 | Polygon | Custom required |
4654

4755
## Token Types
4856

@@ -51,11 +59,15 @@ app.use(x402Express('0xYourAddress', {
5159

5260
## Protocol
5361

54-
Uses x402 v1 with the `exact` scheme. Payments are authorized via EIP-712 signatures and settled by a facilitator service.
62+
Uses **x402 v2** with the `exact` scheme. Payments are authorized via EIP-712 signatures and settled by a facilitator service.
63+
64+
Key v2 features:
65+
- `x402Version: 2` in all payloads
66+
- CAIP-2 network identifiers (e.g., `eip155:8453` instead of `base`)
67+
- Multi-chain support
5568

56-
**Facilitator:** `https://x402.primer.systems`
69+
**Facilitator:** `https://x402.primer.systems` (Base networks only)
5770

5871
## License
5972

6073
MIT - Primer Systems
61-

sdk-python/.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Distribution / packaging
7+
.Python
8+
build/
9+
develop-eggs/
10+
dist/
11+
downloads/
12+
eggs/
13+
.eggs/
14+
lib/
15+
lib64/
16+
parts/
17+
sdist/
18+
var/
19+
wheels/
20+
*.egg-info/
21+
.installed.cfg
22+
*.egg
23+
24+
# Installer logs
25+
pip-log.txt
26+
pip-delete-this-directory.txt
27+
28+
# Unit test / coverage reports
29+
htmlcov/
30+
.tox/
31+
.coverage
32+
.coverage.*
33+
.cache
34+
nosetests.xml
35+
coverage.xml
36+
*.cover
37+
.hypothesis/
38+
.pytest_cache/
39+
40+
# Environments
41+
.env
42+
.venv
43+
env/
44+
venv/
45+
ENV/
46+
env.bak/
47+
venv.bak/
48+
49+
# IDE
50+
.idea/
51+
.vscode/
52+
*.swp
53+
*.swo
54+
55+
# mypy
56+
.mypy_cache/

0 commit comments

Comments
 (0)