You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This directory contains advanced, production-ready patterns for x402 TypeScript clients using fetch. These examples go beyond the basics to demonstrate sophisticated techniques for building robust, scalable payment-enabled applications.
3
+
Advanced patterns for x402 TypeScript clients demonstrating payment lifecycle hooks and network preferences.
4
4
5
-
## What This Shows
6
-
7
-
Advanced patterns for production environments:
8
-
9
-
-**Payment Lifecycle Hooks**: Custom logic at different payment stages
5
+
## Prerequisites
10
6
11
-
## Examples
7
+
- Node.js v20+ (install via [nvm](https://github.com/nvm-sh/nvm))
8
+
- pnpm v10 (install via [pnpm.io/installation](https://pnpm.io/installation))
9
+
- Valid EVM and/or SVM private keys for making payments
10
+
- A running x402 server (see [server examples](../../servers/))
11
+
- Familiarity with the [basic fetch client](../fetch/)
12
12
13
-
### 1. Payment Lifecycle Hooks (`hooks`)
13
+
##Setup
14
14
15
-
**Production Pattern**: Register hooks for payment creation lifecycle events
15
+
1. Copy `.env-local` to `.env`:
16
16
17
17
```bash
18
-
npm start hooks
18
+
cp .env-local .env
19
19
```
20
20
21
-
**Demonstrates:**
21
+
and fill required environment variables:
22
22
23
-
- onBeforePaymentCreation: Custom validation before payment
24
-
- onAfterPaymentCreation: Logging and metrics after payment
This is an example client that demonstrates how to use the `x402-axios` package to make HTTP requests to endpoints protected by the x402 payment protocol.
3
+
Example client demonstrating how to use `@x402/axios` to make HTTP requests to endpoints protected by the x402 payment protocol.
4
4
5
5
## Prerequisites
6
6
7
7
- Node.js v20+ (install via [nvm](https://github.com/nvm-sh/nvm))
8
8
- pnpm v10 (install via [pnpm.io/installation](https://pnpm.io/installation))
9
-
- A running x402 server (you can use the example express server at `examples/typescript/servers/express`)
10
-
-A valid Ethereum private key for making payments
9
+
- A running x402 server (see [express server example](../../servers/express))
10
+
-Valid EVM and/or SVM private keys for making payments
11
11
12
12
## Setup
13
13
14
14
1. Install and build all packages from the typescript examples root:
15
15
```bash
16
16
cd ../../
17
-
pnpm install
18
-
pnpm build
17
+
pnpm install && pnpm build
19
18
cd clients/axios
20
19
```
21
20
22
-
2. Copy `.env-local` to `.env` and add your Ethereum private key:
21
+
2. Copy `.env-local` to `.env` and add your private keys:
23
22
```bash
24
23
cp .env-local .env
25
24
```
26
25
27
-
3. Start the example client:
26
+
Required environment variables:
27
+
-`EVM_PRIVATE_KEY` - Ethereum private key for EVM payments
28
+
-`SVM_PRIVATE_KEY` - Solana private key for SVM payments
Shows how to use convenience helper functions provided by `@x402/evm` and `@x402/svm` packages to register all supported networks with recommended defaults.
0 commit comments