Skip to content

Commit 477e411

Browse files
committed
feat: add Arkade Checkout example app with Lightning payment integration
- Created a new Next.js app for Arkade Checkout example. - Implemented root layout and home page with a "Buy Me a Coffee" feature. - Added success page to confirm payment completion. - Integrated CheckoutModal component for handling payment interactions. - Configured Next.js with Arkade Checkout plugin and necessary environment settings. - Established API routes for creating and claiming payments. - Developed client-side components for checkout and payment status. - Implemented Verifiable Secret Sharing (VSS) for secure private key management. - Added CLI tool for generating credentials and configuration. - Documented setup and usage instructions in README and VSS setup guide.
1 parent f8eb0a4 commit 477e411

32 files changed

Lines changed: 3203 additions & 0 deletions

apps/checkout-example/.env.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Arkade Checkout Configuration
2+
# Run `npx create-arkade-checkout` to generate these values automatically
3+
4+
# Your Arkade private key (generated by create-arkade-checkout)
5+
ARKADE_PRIVATE_KEY_HEX=your_private_key_here
6+
7+
# Production (Mainnet) - Default
8+
ARKADE_SERVER_URL=https://arkade.computer
9+
BOLTZ_API_URL=https://api.ark.boltz.exchange
10+
ARKADE_NETWORK=bitcoin
11+
12+
# Development (Testnet) - Uncomment to use testnet
13+
# ARKADE_SERVER_URL=https://mutinynet.arkade.sh
14+
# BOLTZ_API_URL=https://api.boltz.mutinynet.arkade.sh
15+
# ARKADE_NETWORK=mutinynet
16+
17+
# Optional: Vercel KV for persistent storage (recommended for production)
18+
# KV_REST_API_URL=your_vercel_kv_url
19+
# KV_REST_API_TOKEN=your_vercel_kv_token

apps/checkout-example/README.md

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
# Arkade Checkout Example
2+
3+
A complete Next.js example demonstrating how to integrate Bitcoin Lightning payments using `@arkade-os/checkout`.
4+
5+
## Features
6+
7+
- 💳 Multiple pricing tiers with USD conversion
8+
- ⚡ Lightning Network payments via Arkade + Boltz
9+
- 🎨 Beautiful, responsive UI
10+
- 📱 Mobile-friendly checkout experience
11+
- ✨ Real-time payment status updates
12+
- 🔄 Automatic redirect after successful payment
13+
14+
## Quick Start
15+
16+
### 1. Install Dependencies
17+
18+
```bash
19+
npm install
20+
# or
21+
pnpm install
22+
# or
23+
yarn install
24+
```
25+
26+
### 2. Generate Credentials
27+
28+
```bash
29+
npx create-arkade-checkout
30+
```
31+
32+
This will create a `.env.local` file with your private key and configuration.
33+
34+
### 3. Run Development Server
35+
36+
```bash
37+
npm run dev
38+
# or
39+
pnpm dev
40+
# or
41+
yarn dev
42+
```
43+
44+
Open [http://localhost:3000](http://localhost:3000) in your browser.
45+
46+
## Project Structure
47+
48+
```
49+
example/
50+
├── app/
51+
│ ├── api/
52+
│ │ └── arkade/
53+
│ │ └── [[...path]]/
54+
│ │ └── route.ts # Unified API handler
55+
│ ├── checkout/
56+
│ │ └── [id]/
57+
│ │ └── page.tsx # Checkout page with QR code
58+
│ ├── success/
59+
│ │ └── page.tsx # Success page after payment
60+
│ ├── layout.tsx # Root layout
61+
│ ├── page.tsx # Home page with examples
62+
│ └── globals.css # Global styles
63+
├── public/ # Static files
64+
├── .env.example # Environment variables template
65+
├── next.config.mjs # Next.js config with Arkade plugin
66+
├── package.json
67+
└── tsconfig.json
68+
```
69+
70+
## Environment Variables
71+
72+
Create a `.env.local` file (automatically generated by `npx create-arkade-checkout`):
73+
74+
```env
75+
# Your Arkade private key
76+
ARKADE_PRIVATE_KEY_HEX=your_private_key
77+
78+
# Production (Mainnet) - Default
79+
ARKADE_SERVER_URL=https://arkade.computer
80+
BOLTZ_API_URL=https://api.ark.boltz.exchange
81+
ARKADE_NETWORK=bitcoin
82+
83+
# Development (Testnet)
84+
# ARKADE_SERVER_URL=https://mutinynet.arkade.sh
85+
# BOLTZ_API_URL=https://api.boltz.mutinynet.arkade.sh
86+
# ARKADE_NETWORK=mutinynet
87+
88+
# Optional: Vercel KV for production
89+
# KV_REST_API_URL=your_vercel_kv_url
90+
# KV_REST_API_TOKEN=your_vercel_kv_token
91+
```
92+
93+
## Usage Examples
94+
95+
### Basic Purchase Button
96+
97+
```tsx
98+
"use client";
99+
import { useCheckout } from "@arkade-os/checkout";
100+
101+
export default function BuyButton() {
102+
const { navigate, isNavigating } = useCheckout();
103+
104+
return (
105+
<button
106+
onClick={() =>
107+
navigate({
108+
title: "Premium Plan",
109+
description: "1 year subscription",
110+
amount: 50,
111+
currency: "USD",
112+
metadata: { successUrl: "/success" },
113+
})
114+
}
115+
disabled={isNavigating}
116+
>
117+
Buy Now
118+
</button>
119+
);
120+
}
121+
```
122+
123+
### With BTC Amount
124+
125+
```tsx
126+
navigate({
127+
title: "Premium eBook",
128+
description: "Digital download",
129+
amount: 0.001,
130+
currency: "BTC",
131+
metadata: { successUrl: "/success" },
132+
});
133+
```
134+
135+
### With Satoshis
136+
137+
```tsx
138+
navigate({
139+
title: "Donation",
140+
description: "Support our work",
141+
amount: 10000,
142+
currency: "SAT",
143+
metadata: { successUrl: "/success" },
144+
});
145+
```
146+
147+
### Custom Metadata
148+
149+
```tsx
150+
navigate({
151+
title: "Product Purchase",
152+
description: "Premium widget",
153+
amount: 25,
154+
currency: "USD",
155+
metadata: {
156+
successUrl: "/success",
157+
productId: "widget-123",
158+
customerId: "user-456",
159+
tier: "premium",
160+
},
161+
});
162+
```
163+
164+
## How It Works
165+
166+
1. **User clicks "Buy Now"**`useCheckout().navigate()` is called
167+
2. **Create checkout** → POST to `/api/arkade/create` with payment details
168+
3. **Redirect to checkout** → User sees QR code at `/checkout/[id]`
169+
4. **Payment polling** → Frontend polls `/api/arkade/status?id=[id]`
170+
5. **Background claim** → Server waits for payment via `/api/arkade/claim`
171+
6. **Success redirect** → User redirected to `successUrl` after payment
172+
173+
## API Routes
174+
175+
The example uses the unified route handler that provides:
176+
177+
- `POST /api/arkade/create` - Create new checkout session
178+
- `POST /api/arkade/claim` - Start background payment claim process
179+
- `GET /api/arkade/status?id=[id]` - Check payment status
180+
181+
## Customization
182+
183+
### Styling
184+
185+
The example includes comprehensive CSS in [app/globals.css](app/globals.css). You can:
186+
187+
- Modify CSS variables in `:root` for colors and spacing
188+
- Override `.arkade-checkout-*` classes for widget styling
189+
- Use Tailwind CSS or any other styling solution
190+
191+
### Checkout Component
192+
193+
The checkout page uses the pre-built `<Checkout />` component, but you can create your own:
194+
195+
```tsx
196+
"use client";
197+
import { useState, useEffect } from "react";
198+
199+
export default function CustomCheckout({ id }: { id: string }) {
200+
const [checkout, setCheckout] = useState(null);
201+
202+
useEffect(() => {
203+
fetch(`/api/arkade/status?id=${id}`)
204+
.then((res) => res.json())
205+
.then(setCheckout);
206+
}, [id]);
207+
208+
// Build your custom UI with checkout data
209+
return <div>{/* Your custom checkout UI */}</div>;
210+
}
211+
```
212+
213+
## Testing
214+
215+
### Test Payments
216+
217+
For development/testing:
218+
219+
1. Use testnet configuration in `.env.local`
220+
2. Get testnet Bitcoin from a faucet
221+
3. Use a Lightning testnet wallet (Phoenix, Breez, etc.)
222+
223+
### Production Checklist
224+
225+
- [ ] Environment variables set for mainnet
226+
- [ ] Vercel KV configured (recommended)
227+
- [ ] Test with small amounts first
228+
- [ ] Verify webhook/success URLs are correct
229+
- [ ] Check server function timeout (5min+ recommended)
230+
231+
## Deployment
232+
233+
### Deploy to Vercel
234+
235+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new)
236+
237+
1. Push to GitHub
238+
2. Import to Vercel
239+
3. Add environment variables:
240+
- `ARKADE_PRIVATE_KEY_HEX`
241+
- `ARKADE_SERVER_URL`
242+
- `BOLTZ_API_URL`
243+
- `ARKADE_NETWORK`
244+
4. Optionally configure Vercel KV for storage
245+
5. Deploy!
246+
247+
### Other Platforms
248+
249+
The example works on any platform that supports Next.js:
250+
251+
- Netlify
252+
- Cloudflare Pages
253+
- Railway
254+
- Self-hosted
255+
256+
Make sure your platform supports:
257+
258+
- Next.js 15+
259+
- Server-side functions
260+
- Long-running functions (5min timeout for payment claims)
261+
262+
## Troubleshooting
263+
264+
### "Private key not found"
265+
266+
Run `npx create-arkade-checkout` to generate `.env.local`
267+
268+
### Checkout not found after restart
269+
270+
Using in-memory storage. For production, configure Vercel KV in environment variables.
271+
272+
### Payments not claiming
273+
274+
Check:
275+
276+
- Private key has sufficient balance for swap fees
277+
- Correct Boltz API URL for your network
278+
- Server function timeout is at least 5 minutes
279+
280+
### Module not found errors
281+
282+
If you see import errors, make sure you're in a workspace setup or adjust the import to use the published package:
283+
284+
```tsx
285+
// In workspace (this example)
286+
import { useCheckout } from "@arkade-os/checkout";
287+
288+
// With published package
289+
import { useCheckout } from "@arkade-os/checkout";
290+
```
291+
292+
## Learn More
293+
294+
- [Arkade SDK Documentation](https://github.com/arkade-os/sdk)
295+
- [Boltz Documentation](https://docs.boltz.exchange)
296+
- [Next.js Documentation](https://nextjs.org/docs)
297+
- [Lightning Network](https://lightning.network)
298+
299+
## License
300+
301+
MIT

0 commit comments

Comments
 (0)