Skip to content

Commit cdc0c06

Browse files
authored
Merge pull request #92 from PinataCloud/x402-monetization-sdk
X402 monetization sdk
2 parents 86562b1 + e4c8fe0 commit cdc0c06

Some content is hidden

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

48 files changed

+11711
-12
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
33
"organizeImports": {
44
"enabled": true
55
},
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"_variables": {
3+
"lastUpdateCheck": 1767807090317
4+
}
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="astro/client" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PINATA_JWT=your_pinata_jwt_token_here
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# X402 Monetization Demo
2+
3+
A comprehensive Astro demo application showcasing the complete Pinata X402 Monetization API functionality with file upload, management, and payment instruction workflows.
4+
5+
## Features
6+
7+
### File Management
8+
- Upload files to IPFS via Pinata
9+
- View uploaded files with metadata (CID, size, type, creation date)
10+
- Delete files from Pinata
11+
- Direct links to view files via IPFS gateway
12+
13+
### Payment Instructions
14+
- Create payment instructions with multiple payment requirements
15+
- USDC payments on Base and Base Sepolia networks
16+
- View and manage existing payment instructions
17+
- Update and delete payment instructions
18+
19+
### CID-Payment Association
20+
- Associate uploaded file CIDs with payment instructions
21+
- Attach multiple CIDs to a single payment instruction
22+
- Each CID can only have one payment instruction at a time
23+
- View and remove CID associations
24+
25+
### Auto-Run Demo
26+
- **🚀 One-click complete workflow demonstration**
27+
- Automatically generates unique timestamped test files
28+
- Uploads files and creates payment instructions
29+
- Associates CIDs with payment instructions
30+
- Provides detailed step-by-step results
31+
- Perfect for testing and demonstrating the entire API flow
32+
33+
## Setup
34+
35+
1. Copy `.env.example` to `.env` and add your Pinata JWT:
36+
```bash
37+
cp .env.example .env
38+
```
39+
40+
2. Install dependencies:
41+
```bash
42+
npm install
43+
```
44+
45+
3. Start the development server:
46+
```bash
47+
npm run dev
48+
```
49+
50+
4. Open your browser to `http://localhost:4321`
51+
52+
## Environment Variables
53+
54+
- `PINATA_JWT` - Your Pinata API JWT token (required)
55+
56+
## API Endpoints
57+
58+
The demo includes the following API routes:
59+
60+
### File Management
61+
- `GET /api/files` - List uploaded files
62+
- `POST /api/files` - Upload new file
63+
- `GET /api/files/[id]` - Get file information
64+
- `PATCH /api/files/[id]` - Update file metadata
65+
- `DELETE /api/files/[id]` - Delete file
66+
67+
### Payment Instructions
68+
- `GET /api/payment-instructions` - List payment instructions
69+
- `POST /api/payment-instructions` - Create payment instruction
70+
- `GET /api/payment-instructions/[id]` - Get payment instruction
71+
- `PATCH /api/payment-instructions/[id]` - Update payment instruction
72+
- `DELETE /api/payment-instructions/[id]` - Delete payment instruction
73+
74+
### CID Management
75+
- `GET /api/payment-instructions/[id]/cids` - List CIDs for payment instruction
76+
- `PUT /api/payment-instructions/[id]/cids/[cid]` - Add CID to payment instruction
77+
- `DELETE /api/payment-instructions/[id]/cids/[cid]` - Remove CID from payment instruction
78+
79+
### Auto-Run Demo
80+
- `POST /api/auto-run` - Execute complete demo workflow
81+
82+
## Usage
83+
84+
### Quick Start - Auto-Run Demo
85+
1. **🚀 Click "Run Complete Demo"** - This will automatically execute the entire workflow:
86+
- Generate a unique test file with timestamp
87+
- Upload it to IPFS
88+
- Create a payment instruction with USDC on Base Sepolia
89+
- Associate the CID with the payment instruction
90+
- Display detailed results
91+
92+
### Manual Workflow
93+
1. **Upload Files**: Use the file upload form to upload content to IPFS and get CIDs.
94+
95+
2. **Create Payment Instructions**: Fill out the form with payment details:
96+
- **Asset**: Contract address (e.g., `0x036CbD53842c5426634e7929541eC2318f3dCF7e`)
97+
- **Pay To Address**: Recipient wallet address
98+
- **Network**: `base`, `base-sepolia`, `eip155:8453`, or `eip155:84532`
99+
- **Amount**: Amount in smallest unit (e.g., `1000000` for token amounts)
100+
101+
3. **Associate Files with Payments**: Click "Attach Payment" on any file to associate it with existing payment instructions.
102+
103+
4. **View and Manage**:
104+
- View all files with their metadata and gateway links
105+
- View payment instructions with their requirements
106+
- Manage CID associations through modals
107+
108+
5. **Delete and Clean Up**: Remove files, payment instructions, or associations as needed.
109+
110+
## Project Structure
111+
112+
```
113+
src/
114+
├── components/ # Reusable Astro components
115+
├── layouts/ # Page layouts
116+
├── pages/ # Pages and API routes
117+
│ ├── api/ # API endpoints
118+
│ └── index.astro # Main page
119+
└── public/ # Static assets
120+
```
121+
122+
## Technologies Used
123+
124+
- [Astro](https://astro.build/) - Web framework
125+
- [Pinata SDK](https://docs.pinata.cloud/) - X402 Monetization API
126+
- Vanilla JavaScript - Frontend interactions
127+
- CSS - Styling
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'astro/config';
2+
import node from '@astrojs/node';
3+
4+
export default defineConfig({
5+
output: 'server',
6+
adapter: node({
7+
mode: 'standalone'
8+
}),
9+
server: {
10+
port: 4321
11+
}
12+
});

0 commit comments

Comments
 (0)