@payai/x402-next-starter 0.1.1
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 +201 -0
- package/NOTICE +2 -0
- package/README.md +85 -0
- package/bin/create.js +87 -0
- package/package.json +39 -0
- package/template/.env-local +3 -0
- package/template/.prettierignore +8 -0
- package/template/.prettierrc +11 -0
- package/template/README.md +127 -0
- package/template/app/assets/x402_wordmark_dark.png +0 -0
- package/template/app/assets/x402_wordmark_dark.svg +4 -0
- package/template/app/assets/x402_wordmark_light.svg +1 -0
- package/template/app/favicon.ico +0 -0
- package/template/app/globals.css +33 -0
- package/template/app/layout.tsx +51 -0
- package/template/app/page.tsx +51 -0
- package/template/app/protected/page.tsx +16 -0
- package/template/eslint.config.js +73 -0
- package/template/middleware.ts +31 -0
- package/template/next.config.ts +17 -0
- package/template/package-lock.json +8726 -0
- package/template/package.json +42 -0
- package/template/postcss.config.mjs +8 -0
- package/template/public/apple-touch-icon.png +0 -0
- package/template/public/favicon-96x96.png +0 -0
- package/template/public/favicon.svg +3 -0
- package/template/public/site.webmanifest +21 -0
- package/template/public/web-app-manifest-192x192.png +0 -0
- package/template/public/web-app-manifest-512x512.png +0 -0
- package/template/public/x402-icon-blue.png +0 -0
- package/template/tailwind.config.ts +18 -0
- package/template/tsconfig.json +27 -0
- package/template/types/svg.d.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# x402 Next.js Starter
|
|
2
|
+
|
|
3
|
+
Create an x402 Next.js app in less than 2 minutes!
|
|
4
|
+
|
|
5
|
+
This package provides a complete Next.js application template with x402 payment protocol integration, allowing you to quickly set up a web application with payment middleware.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @payai/x402-next-starter my-app
|
|
11
|
+
cd my-app
|
|
12
|
+
cp env.example .env.local
|
|
13
|
+
# Edit .env.local with your configuration
|
|
14
|
+
npm run dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## What's Included
|
|
18
|
+
|
|
19
|
+
- ⚡ **Next.js 14** with App Router
|
|
20
|
+
- 💳 **x402 payment middleware** integration
|
|
21
|
+
- 🎨 **Tailwind CSS** for styling
|
|
22
|
+
- 📝 **TypeScript** support
|
|
23
|
+
- 🔧 **ESLint and Prettier** configuration
|
|
24
|
+
- 🚀 **Ready-to-deploy** API routes
|
|
25
|
+
- 📖 **Comprehensive documentation**
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
### Payment Integration
|
|
30
|
+
- x402 payment middleware for protecting routes
|
|
31
|
+
- Support for multiple networks (Base, Solana)
|
|
32
|
+
- Configurable payment amounts and tokens
|
|
33
|
+
- Automatic payment verification
|
|
34
|
+
|
|
35
|
+
### Developer Experience
|
|
36
|
+
- TypeScript for type safety
|
|
37
|
+
- ESLint and Prettier for code quality
|
|
38
|
+
- Hot reloading in development
|
|
39
|
+
- Production-ready build configuration
|
|
40
|
+
|
|
41
|
+
### Example Implementation
|
|
42
|
+
- Free weather API endpoint
|
|
43
|
+
- Premium content with payment protection
|
|
44
|
+
- Modern, responsive UI
|
|
45
|
+
- Clear documentation and examples
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
After creating your app, you'll need to configure:
|
|
50
|
+
|
|
51
|
+
1. **Environment Variables**: Update `.env.local` with your wallet address and facilitator URL
|
|
52
|
+
2. **Payment Settings**: Customize payment amounts and networks in `middleware.ts`
|
|
53
|
+
3. **Styling**: Modify Tailwind CSS classes or add custom styles
|
|
54
|
+
|
|
55
|
+
## Project Structure
|
|
56
|
+
|
|
57
|
+
The generated app includes:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
├── app/
|
|
61
|
+
│ ├── api/ # API routes
|
|
62
|
+
│ ├── premium/ # Premium content page
|
|
63
|
+
│ ├── globals.css # Global styles
|
|
64
|
+
│ ├── layout.tsx # Root layout
|
|
65
|
+
│ └── page.tsx # Home page
|
|
66
|
+
├── middleware.ts # x402 payment middleware
|
|
67
|
+
├── next.config.js # Next.js configuration
|
|
68
|
+
├── tailwind.config.js # Tailwind CSS configuration
|
|
69
|
+
├── tsconfig.json # TypeScript configuration
|
|
70
|
+
└── package.json # Dependencies and scripts
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Learn More
|
|
74
|
+
|
|
75
|
+
- [x402 Protocol Documentation](https://github.com/coinbase/x402)
|
|
76
|
+
- [Next.js Documentation](https://nextjs.org/docs)
|
|
77
|
+
- [Tailwind CSS Documentation](https://tailwindcss.com/docs)
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
Apache-2.0
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/bin/create.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import url from 'url';
|
|
6
|
+
import { execSync } from 'child_process';
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
9
|
+
const repoRoot = path.join(__dirname, '..');
|
|
10
|
+
const templateDir = path.join(repoRoot, 'template');
|
|
11
|
+
|
|
12
|
+
const args = process.argv.slice(2);
|
|
13
|
+
const nameArg = args.find((a) => !a.startsWith('-'));
|
|
14
|
+
const projectName = nameArg || 'my-x402-next-app';
|
|
15
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
16
|
+
|
|
17
|
+
if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length) {
|
|
18
|
+
console.error(`\nTarget directory '${projectName}' is not empty. Choose another name or empty it.\n`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// copy template
|
|
23
|
+
fs.cpSync(templateDir, targetDir, { recursive: true });
|
|
24
|
+
|
|
25
|
+
// ensure the root package.json name matches the project
|
|
26
|
+
const rootPkgPath = path.join(targetDir, 'package.json');
|
|
27
|
+
if (fs.existsSync(rootPkgPath)) {
|
|
28
|
+
const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, 'utf8'));
|
|
29
|
+
rootPkg.name = projectName.replace(/[^a-zA-Z0-9-_./@]/g, '-');
|
|
30
|
+
fs.writeFileSync(rootPkgPath, JSON.stringify(rootPkg, null, 2));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// perform post-scaffold steps for convenience
|
|
34
|
+
console.log(`\nSetting up your project in: ${targetDir}`);
|
|
35
|
+
|
|
36
|
+
// 1) Copy environment template for Next.js (.env.local preferred)
|
|
37
|
+
try {
|
|
38
|
+
// Look for common env template filenames in priority order
|
|
39
|
+
const candidates = [
|
|
40
|
+
{ file: 'env.local', label: 'env.local' },
|
|
41
|
+
{ file: '.env-local', label: '.env-local' },
|
|
42
|
+
{ file: 'env.example', label: 'env.example' },
|
|
43
|
+
{ file: '.env.example', label: '.env.example' },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const found = candidates
|
|
47
|
+
.map((c) => ({ ...c, abs: path.join(targetDir, c.file) }))
|
|
48
|
+
.find((c) => fs.existsSync(c.abs));
|
|
49
|
+
|
|
50
|
+
const envTarget = path.join(targetDir, '.env');
|
|
51
|
+
|
|
52
|
+
if (found) {
|
|
53
|
+
console.log(`- Creating .env from ${found.label}`);
|
|
54
|
+
fs.copyFileSync(found.abs, envTarget);
|
|
55
|
+
} else {
|
|
56
|
+
console.log('- No env template found; please create .env manually');
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.warn('- Skipped env setup:', err instanceof Error ? err.message : String(err));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 2) Install dependencies (always)
|
|
63
|
+
try {
|
|
64
|
+
console.log('- Installing dependencies (npm install)...');
|
|
65
|
+
execSync('npm install', { stdio: 'inherit', cwd: targetDir });
|
|
66
|
+
} catch (err) {
|
|
67
|
+
console.warn('- npm install failed, you may run it manually:', err instanceof Error ? err.message : String(err));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// init git (best-effort)
|
|
71
|
+
try {
|
|
72
|
+
execSync('git init', { stdio: 'ignore', cwd: targetDir });
|
|
73
|
+
} catch {}
|
|
74
|
+
|
|
75
|
+
// print next steps
|
|
76
|
+
console.log(`
|
|
77
|
+
Successfully created ${projectName}!
|
|
78
|
+
|
|
79
|
+
You now have a starter example for a Next.js app integrated with x402.
|
|
80
|
+
|
|
81
|
+
Next steps:
|
|
82
|
+
cd ${projectName}
|
|
83
|
+
# edit values inside .env
|
|
84
|
+
npm run dev
|
|
85
|
+
|
|
86
|
+
Happy building 🏗️
|
|
87
|
+
`);
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@payai/x402-next-starter",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Create an x402 Next.js app in less than 2 minutes!",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-x402-next": "bin/create.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"template/**",
|
|
12
|
+
"bin/**",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"NOTICE",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"x402",
|
|
23
|
+
"nextjs",
|
|
24
|
+
"next",
|
|
25
|
+
"typescript",
|
|
26
|
+
"coinbase",
|
|
27
|
+
"starter",
|
|
28
|
+
"template",
|
|
29
|
+
"example"
|
|
30
|
+
],
|
|
31
|
+
"author": "PayAI",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/PayAINetwork/x402-next-starter"
|
|
35
|
+
},
|
|
36
|
+
"config": {
|
|
37
|
+
"x402NextVersion": "0.6.5"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# x402-next Example App
|
|
2
|
+
|
|
3
|
+
This is a Next.js application that demonstrates how to use the `x402-next` middleware to implement paywall functionality in your Next.js routes.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
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
|
+
- A valid Ethereum address for receiving payments
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
1. Copy `.env-local` to `.env` and add your Ethereum address to receive payments:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cp .env-local .env
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. Install and build all packages from the typescript examples root:
|
|
20
|
+
```bash
|
|
21
|
+
cd ../../
|
|
22
|
+
pnpm install
|
|
23
|
+
pnpm build
|
|
24
|
+
cd fullstack/next
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
2. Install and start the Next.js example:
|
|
28
|
+
```bash
|
|
29
|
+
pnpm dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Example Routes
|
|
33
|
+
|
|
34
|
+
The app includes protected routes that require payment to access:
|
|
35
|
+
|
|
36
|
+
### Protected Page Route
|
|
37
|
+
The `/protected` route requires a payment of $0.01 to access. The route is protected using the x402-next middleware:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// middleware.ts
|
|
41
|
+
import { paymentMiddleware, Network, Resource } from "x402-next";
|
|
42
|
+
|
|
43
|
+
const facilitatorUrl = process.env.NEXT_PUBLIC_FACILITATOR_URL as Resource;
|
|
44
|
+
const payTo = process.env.RESOURCE_WALLET_ADDRESS as Address;
|
|
45
|
+
const network = process.env.NETWORK as Network;
|
|
46
|
+
|
|
47
|
+
export const middleware = paymentMiddleware(
|
|
48
|
+
payTo,
|
|
49
|
+
{
|
|
50
|
+
"/protected": {
|
|
51
|
+
price: "$0.01",
|
|
52
|
+
network,
|
|
53
|
+
config: {
|
|
54
|
+
description: "Access to protected content",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
url: facilitatorUrl,
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Configure which paths the middleware should run on
|
|
64
|
+
export const config = {
|
|
65
|
+
matcher: ["/protected/:path*"],
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Response Format
|
|
70
|
+
|
|
71
|
+
### Payment Required (402)
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"error": "X-PAYMENT header is required",
|
|
75
|
+
"paymentRequirements": {
|
|
76
|
+
"scheme": "exact",
|
|
77
|
+
"network": "base",
|
|
78
|
+
"maxAmountRequired": "1000",
|
|
79
|
+
"resource": "http://localhost:3000/protected",
|
|
80
|
+
"description": "Access to protected content",
|
|
81
|
+
"mimeType": "",
|
|
82
|
+
"payTo": "0xYourAddress",
|
|
83
|
+
"maxTimeoutSeconds": 60,
|
|
84
|
+
"asset": "0x...",
|
|
85
|
+
"outputSchema": null,
|
|
86
|
+
"extra": null
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Successful Response
|
|
92
|
+
```ts
|
|
93
|
+
// Headers
|
|
94
|
+
{
|
|
95
|
+
"X-PAYMENT-RESPONSE": "..." // Encoded response object
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Extending the Example
|
|
100
|
+
|
|
101
|
+
To add more protected routes, update the middleware configuration:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
export const middleware = paymentMiddleware(
|
|
105
|
+
payTo,
|
|
106
|
+
{
|
|
107
|
+
"/protected": {
|
|
108
|
+
price: "$0.01",
|
|
109
|
+
network,
|
|
110
|
+
config: {
|
|
111
|
+
description: "Access to protected content",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
"/api/premium": {
|
|
115
|
+
price: "$0.10",
|
|
116
|
+
network,
|
|
117
|
+
config: {
|
|
118
|
+
description: "Premium API access",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
export const config = {
|
|
125
|
+
matcher: ["/protected/:path*", "/api/premium/:path*"],
|
|
126
|
+
};
|
|
127
|
+
```
|
|
Binary file
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg width="156" height="48" viewBox="0 0 156 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M0.224 47L12.96 29.656L0.8 12.952H7.648L16.48 25.816H16.672L25.504 12.952H32.16L20 29.464L32.8 47H25.952L16.48 33.304H16.288L6.88 47H0.224Z" fill="#464B55"/>
|
|
3
|
+
<path d="M40.2015 35.864V31L60.0415 1.944H67.4015V30.872H74.5695V35.864H67.4015V47H61.4495V35.864H40.2015ZM46.2175 30.616V30.872H61.5775V8.536H61.2575L46.2175 30.616ZM98.355 0.983997C108.531 0.983997 114.739 7.768 114.739 18.776V29.976C114.739 41.24 108.467 47.896 98.355 47.896C88.307 47.896 81.971 41.24 81.971 29.976V18.776C81.971 7.768 88.243 0.983997 98.355 0.983997ZM98.355 42.584C104.883 42.584 108.723 37.784 108.723 29.976V18.84C108.723 11.16 104.883 6.296 98.355 6.296C91.827 6.296 87.987 11.16 87.987 18.84V29.976C87.987 37.784 91.827 42.584 98.355 42.584ZM123.485 47V41.688C123.485 36.056 126.493 32.216 133.213 28.376L142.621 23C147.741 20.056 148.829 17.176 148.829 14.296V13.528C148.829 9.304 145.885 5.912 139.869 5.912C134.045 5.912 130.333 9.368 130.269 15.384H124.381C124.509 6.232 130.973 0.983997 139.869 0.983997C149.085 0.983997 154.909 6.36 154.909 13.72C154.909 18.712 152.797 23.256 145.821 27.288L135.837 33.048C131.357 35.736 129.437 37.976 129.437 41.496V41.88H155.805V47H123.485Z" fill="white"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg fill="none" height="48" viewBox="0 0 156 48" width="156" xmlns="http://www.w3.org/2000/svg"><path d="m.224 47 12.736-17.344-12.16-16.704h6.848l8.832 12.864h.192l8.832-12.864h6.656l-12.16 16.512 12.8 17.536h-6.848l-9.472-13.696h-.192l-9.408 13.696z" fill="#bfc4cf"/><path d="m40.2015 35.864v-4.864l19.84-29.056h7.36v28.928h7.168v4.992h-7.168v11.136h-5.952v-11.136zm6.016-5.248v.256h15.36v-22.336h-.32zm52.1375-29.632003c10.176 0 16.384 6.784003 16.384 17.792003v11.2c0 11.264-6.272 17.92-16.384 17.92-10.048 0-16.384-6.656-16.384-17.92v-11.2c0-11.008 6.272-17.792003 16.384-17.792003zm0 41.600003c6.528 0 10.368-4.8 10.368-12.608v-11.136c0-7.68-3.84-12.544-10.368-12.544s-10.368 4.864-10.368 12.544v11.136c0 7.808 3.84 12.608 10.368 12.608zm25.13 4.416v-5.312c0-5.632 3.008-9.472 9.728-13.312l9.408-5.376c5.12-2.944 6.208-5.824 6.208-8.704v-.768c0-4.224-2.944-7.616-8.96-7.616-5.824 0-9.536 3.456-9.6 9.472h-5.888c.128-9.152 6.592-14.400003 15.488-14.400003 9.216 0 15.04 5.376003 15.04 12.736003 0 4.992-2.112 9.536-9.088 13.568l-9.984 5.76c-4.48 2.688-6.4 4.928-6.4 8.448v.384h26.368v5.12z" fill="#000"/></svg>
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
:root {
|
|
6
|
+
--background: #ffffff;
|
|
7
|
+
--foreground: #171717;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (prefers-color-scheme: dark) {
|
|
11
|
+
:root {
|
|
12
|
+
--background: #1a1a2e;
|
|
13
|
+
--foreground: #ededed;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
body {
|
|
18
|
+
color: var(--foreground);
|
|
19
|
+
background: var(--background);
|
|
20
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@layer utilities {
|
|
24
|
+
.full-bleed {
|
|
25
|
+
width: 100vw;
|
|
26
|
+
margin-left: calc(50% - 50vw);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.unset-full-bleed {
|
|
30
|
+
width: unset;
|
|
31
|
+
margin-left: unset;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Metadata } from "next";
|
|
2
|
+
import { Geist, Geist_Mono } from "next/font/google";
|
|
3
|
+
import "./globals.css";
|
|
4
|
+
|
|
5
|
+
const geistSans = Geist({
|
|
6
|
+
variable: "--font-geist-sans",
|
|
7
|
+
subsets: ["latin"],
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const geistMono = Geist_Mono({
|
|
11
|
+
variable: "--font-geist-mono",
|
|
12
|
+
subsets: ["latin"],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const metadata: Metadata = {
|
|
16
|
+
title: 'x402.org',
|
|
17
|
+
description: 'A chain-agnostic protocol for web payments',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function RootLayout({
|
|
21
|
+
children,
|
|
22
|
+
}: Readonly<{
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
}>) {
|
|
25
|
+
return (
|
|
26
|
+
<html lang="en">
|
|
27
|
+
<head>
|
|
28
|
+
<link rel="icon" href="/favicon.ico" sizes="any" />
|
|
29
|
+
<link
|
|
30
|
+
rel="icon"
|
|
31
|
+
type="image/png"
|
|
32
|
+
href="/favicon-96x96.png"
|
|
33
|
+
sizes="96x96"
|
|
34
|
+
/>
|
|
35
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
36
|
+
<link
|
|
37
|
+
rel="apple-touch-icon"
|
|
38
|
+
sizes="180x180"
|
|
39
|
+
href="/apple-touch-icon.png"
|
|
40
|
+
/>
|
|
41
|
+
<meta name="apple-mobile-web-app-title" content="x402" />
|
|
42
|
+
<link rel="manifest" href="/site.webmanifest" />
|
|
43
|
+
</head>
|
|
44
|
+
<body
|
|
45
|
+
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
|
46
|
+
>
|
|
47
|
+
{children}
|
|
48
|
+
</body>
|
|
49
|
+
</html>
|
|
50
|
+
);
|
|
51
|
+
}
|