@circle-fin/x402-batching 2.0.3
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/README.md +123 -0
- package/dist/client/index.d.mts +653 -0
- package/dist/client/index.d.ts +653 -0
- package/dist/client/index.js +1313 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +1282 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/index.d.mts +62 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +33 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server/index.d.mts +318 -0
- package/dist/server/index.d.ts +318 -0
- package/dist/server/index.js +697 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +668 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/types-DnHgU28a.d.mts +90 -0
- package/dist/types-DnHgU28a.d.ts +90 -0
- package/package.json +95 -0
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# x402-batching
|
|
2
|
+
|
|
3
|
+
**Gasless micropayments via Circle Gateway.**
|
|
4
|
+
|
|
5
|
+
This SDK allows you to add **gasless payments** to your application using the open [x402 protocol](https://x402.org). Payments are signed off-chain and settled in batches by [Circle Gateway](https://developers.circle.com/gateway).
|
|
6
|
+
|
|
7
|
+
## Integration at a Glance
|
|
8
|
+
|
|
9
|
+
### 1. Simple Integration (Express)
|
|
10
|
+
|
|
11
|
+
Monetize any API route with **2 lines of code**:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// Seller
|
|
15
|
+
const gateway = createGatewayMiddleware({ sellerAddress: '0x...' });
|
|
16
|
+
app.get('/premium', gateway.require('$0.01'), (req, res) => res.json({ ... }));
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Pay for it **without gas**:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
// Buyer
|
|
23
|
+
const client = new GatewayClient({ chain: 'arcTestnet', privateKey });
|
|
24
|
+
await client.pay('https://api.example.com/premium');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 2. Using standard @x402/core?
|
|
28
|
+
|
|
29
|
+
If you already use the standard x402 library, just add Gateway support:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { x402ResourceServer } from '@x402/core/server';
|
|
33
|
+
import { BatchFacilitatorClient } from '@circle-fin/x402-batching/server';
|
|
34
|
+
|
|
35
|
+
const server = new x402ResourceServer([
|
|
36
|
+
// Add Gateway alongside your other facilitators
|
|
37
|
+
new BatchFacilitatorClient(),
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
await server.initialize();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install @circle-fin/x402-batching
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This will also install the required peer dependencies (`@x402/core`, `viem`). The optional peer dependency `@x402/evm` is only needed if using `CompositeEvmScheme` or `GatewayEvmScheme` — see [Migration Guide](./docs/MIGRATION_GUIDE.md) for details.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
Experience the flow immediately with our **Paywall Demo**.
|
|
58
|
+
|
|
59
|
+
1. **Clone & Build**
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/crcl-main/x402-batching-sdk-internal.git
|
|
63
|
+
cd x402-batching-sdk-internal
|
|
64
|
+
nvm install && nvm use && npm install && npm run build
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
2. **Run the Demo**
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
cd examples/basic-paywall
|
|
71
|
+
npm install
|
|
72
|
+
|
|
73
|
+
# Terminal 1: Start Seller
|
|
74
|
+
npm run server
|
|
75
|
+
|
|
76
|
+
# Terminal 2: Run Buyer (Requires Testnet USDC)
|
|
77
|
+
export PRIVATE_KEY=0x...
|
|
78
|
+
npm run deposit # One-time deposit
|
|
79
|
+
npm run client # Pay for resource gaslessly
|
|
80
|
+
npm run client # Pay for resource gaslessly
|
|
81
|
+
npm run client # Pay for resource gaslessly
|
|
82
|
+
...
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
> **Need Funds?** Get testnet USDC from the [Circle Faucet](https://faucet.circle.com) (Select "Arc Testnet").
|
|
86
|
+
>
|
|
87
|
+
> **Need more?** The public faucet has limits. Use the [Developer Console Faucet API](https://developers.circle.com/w3s/developer-console-faucet#fund-a-wallet-programmatically) with your API key for higher limits:
|
|
88
|
+
>
|
|
89
|
+
> ```bash
|
|
90
|
+
> curl -X POST https://api.circle.com/v1/faucet/drips \
|
|
91
|
+
> -H 'Authorization: Bearer KEY' -H 'Content-Type: application/json' \
|
|
92
|
+
> -d '{"address": "0x...", "blockchain": "ARC", "usdc": true}'
|
|
93
|
+
> ```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Documentation
|
|
98
|
+
|
|
99
|
+
| Guide | Description |
|
|
100
|
+
| ---------------------------------------------------------- | ------------------------------------------------------------ |
|
|
101
|
+
| [**Concepts**](./docs/CONCEPTS.md) | Understand how gasless payments work. |
|
|
102
|
+
| [**Seller Guide**](./docs/SELLER_GUIDE.md) | How to monetize your API. |
|
|
103
|
+
| [**Buyer Guide**](./docs/BUYER_GUIDE.md) | How to pay for resources and withdraw funds. |
|
|
104
|
+
| [**Facilitator Guide**](./docs/FACILITATOR_INTEGRATION.md) | For infrastructure providers to add gasless payment support. |
|
|
105
|
+
| [**SDK Reference**](./docs/SDK_REFERENCE.md) | Detailed SDK documentation. |
|
|
106
|
+
|
|
107
|
+
## Supported Networks
|
|
108
|
+
|
|
109
|
+
Circle Gateway connects multiple blockchains for instant cross-chain liquidity.
|
|
110
|
+
|
|
111
|
+
- **Gasless Payments**: Currently supported on **[Arc Testnet](https://arc.network)**.
|
|
112
|
+
- **Deposits & Withdrawals**: Supported on many EVM chains.
|
|
113
|
+
|
|
114
|
+
See [**Networks & Addresses**](./docs/NETWORKS.md) for the full list of chain IDs and contracts.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Try Our Demos
|
|
119
|
+
|
|
120
|
+
| Demo | Description |
|
|
121
|
+
| -------------------------------------------------- | ------------------------------------------------------- |
|
|
122
|
+
| [**Basic Paywall**](./examples/basic-paywall/) | Simple E2E example with a Seller API and Buyer script. |
|
|
123
|
+
| [**Digital Dungeon**](./examples/digital-dungeon/) | Interactive adventure game demonstrating micropayments. |
|