|
1 | 1 | # Arc Commerce |
2 | 2 |
|
3 | | -This project demonstrates how to integrate USDC as a payment method for purchasing credits on Arc. |
| 3 | +Integrate USDC as a payment method for purchasing credits on Arc. This sample application uses Next.js, Supabase, and Circle Developer Controlled Wallets to demonstrate a credit purchase flow with USDC payments on Arc testnet. |
4 | 4 |
|
5 | | -## Table of Contents |
| 5 | +<img width="830" height="646" alt="User dashboard for credit purchase" src="public/screenshot.png" /> |
6 | 6 |
|
7 | | -- [Clone and Run Locally](#clone-and-run-locally) |
8 | | -- [Environment Variables](#environment-variables) |
| 7 | +## Prerequisites |
9 | 8 |
|
10 | | -## Clone and Run Locally |
| 9 | +- Node.js 20.x or newer |
| 10 | +- npm (automatically installed when Node.js is installed) |
| 11 | +- Docker (for running Supabase locally) |
| 12 | +- [ngrok](https://ngrok.com/) (for local webhook testing) |
| 13 | +- Circle Developer Controlled Wallets [API key](https://console.circle.com/signin) and [Entity Secret](https://developers.circle.com/wallets/dev-controlled/register-entity-secret) |
11 | 14 |
|
12 | | -1. **Clone and install dependencies:** |
| 15 | +## Getting Started |
| 16 | + |
| 17 | +1. Clone the repository and install dependencies: |
13 | 18 |
|
14 | 19 | ```bash |
15 | 20 | git clone git@github.com:circlefin/arc-commerce.git |
16 | 21 | cd arc-commerce |
17 | 22 | npm install |
18 | 23 | ``` |
19 | 24 |
|
20 | | -2. **Set up environment variables:** |
| 25 | +2. Create a `.env.local` file in the project root: |
21 | 26 |
|
22 | 27 | ```bash |
23 | 28 | cp .env.example .env.local |
24 | 29 | ``` |
25 | 30 |
|
26 | | - Then edit `.env.local` and fill in all required values (see [Environment Variables](#environment-variables) section below). |
| 31 | + Required variables: |
| 32 | + |
| 33 | + ```bash |
| 34 | + # Supabase |
| 35 | + NEXT_PUBLIC_SUPABASE_URL=your_supabase_url |
| 36 | + NEXT_PUBLIC_SUPABASE_PUBLISHABLE_OR_ANON_KEY=your_anon_key |
| 37 | + SUPABASE_SERVICE_ROLE_KEY=your_service_role_key |
| 38 | + |
| 39 | + # Circle |
| 40 | + CIRCLE_API_KEY=your_circle_api_key |
| 41 | + CIRCLE_ENTITY_SECRET=your_entity_secret |
| 42 | + CIRCLE_BLOCKCHAIN=ARC-TESTNET |
| 43 | + CIRCLE_USDC_TOKEN_ID=15dc2b5d-0994-58b0-bf8c-3a0501148ee8 |
| 44 | + |
| 45 | + # Misc |
| 46 | + ADMIN_EMAIL=admin@admin.com |
| 47 | + ``` |
27 | 48 |
|
28 | | -3. **Start Supabase locally** (requires Docker): |
| 49 | +3. Start Supabase locally: |
29 | 50 |
|
30 | 51 | ```bash |
31 | 52 | npx supabase start |
32 | 53 | npx supabase migration up |
33 | 54 | ``` |
34 | 55 |
|
35 | | -4. **Start the development server:** |
| 56 | +4. Start the development server: |
36 | 57 |
|
37 | 58 | ```bash |
38 | 59 | npm run dev |
39 | 60 | ``` |
40 | 61 |
|
41 | | - The app will be available at [http://localhost:3000](http://localhost:3000/). The admin wallet will be automatically created on first startup. |
| 62 | + The app will be available at `http://localhost:3000`. The admin wallet is automatically created on first startup. |
42 | 63 |
|
43 | | -5. **Set up Circle Webhooks:** |
| 64 | +5. Set up Circle Webhooks (for local development): |
44 | 65 |
|
45 | | - In a separate terminal, start ngrok to expose your local server: |
| 66 | + In a separate terminal, expose your local server: |
46 | 67 |
|
47 | 68 | ```bash |
48 | 69 | ngrok http 3000 |
49 | 70 | ``` |
50 | 71 |
|
51 | | - Copy the HTTPS URL from ngrok (e.g., `https://your-ngrok-url.ngrok.io`) and add it to your Circle Console webhooks section: |
| 72 | + Add the webhook endpoint in Circle Console: |
52 | 73 | - Navigate to Circle Console → Webhooks |
53 | | - - Add a new webhook endpoint: `https://your-ngrok-url.ngrok.io/api/circle/webhook` |
54 | | - - Keep ngrok running while developing to receive webhook events |
| 74 | + - Add endpoint: `https://your-ngrok-url.ngrok.io/api/circle/webhook` |
| 75 | + - Keep ngrok running to receive webhook events |
| 76 | + |
| 77 | +## How It Works |
| 78 | + |
| 79 | +- Built with [Next.js](https://nextjs.org/) and [Supabase](https://supabase.com/) |
| 80 | +- Uses [Circle Developer Controlled Wallets](https://developers.circle.com/wallets/dev-controlled) for USDC transactions |
| 81 | +- Wallet operations handled server-side with `@circle-fin/developer-controlled-wallets` |
| 82 | +- Webhook signature verification ensures secure transaction notifications |
| 83 | +- Admin wallet automatically initialized on first run |
55 | 84 |
|
56 | 85 | ## Environment Variables |
57 | 86 |
|
58 | | -Copy `.env.example` to `.env.local` and fill in the required values: |
| 87 | +| Variable | Scope | Purpose | |
| 88 | +| ------------------------------------- | ----------- | ------------------------------------------------------------------------ | |
| 89 | +| `NEXT_PUBLIC_SUPABASE_URL` | Public | Supabase project URL | |
| 90 | +| `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_OR_ANON_KEY` | Public | Supabase anonymous/public key | |
| 91 | +| `SUPABASE_SERVICE_ROLE_KEY` | Server-side | Service role for privileged database operations | |
| 92 | +| `CIRCLE_API_KEY` | Server-side | Circle API key for webhook signature verification | |
| 93 | +| `CIRCLE_ENTITY_SECRET` | Server-side | Circle entity secret for wallet operations | |
| 94 | +| `CIRCLE_BLOCKCHAIN` | Server-side | Blockchain network identifier (e.g., "ARC-TESTNET") | |
| 95 | +| `CIRCLE_USDC_TOKEN_ID` | Server-side | USDC token ID for the specified blockchain | |
| 96 | +| `ADMIN_EMAIL` | Server-side | Email address that determines which user gets admin dashboard access | |
59 | 97 |
|
60 | | -```bash |
61 | | -# Supabase |
62 | | -NEXT_PUBLIC_SUPABASE_URL= |
63 | | -NEXT_PUBLIC_SUPABASE_PUBLISHABLE_OR_ANON_KEY= |
64 | | -SUPABASE_SERVICE_ROLE_KEY= |
| 98 | +## Usage Notes |
65 | 99 |
|
66 | | -# Circle |
67 | | -CIRCLE_API_KEY= |
68 | | -CIRCLE_ENTITY_SECRET= |
69 | | -CIRCLE_BLOCKCHAIN=ARC-TESTNET |
70 | | -CIRCLE_USDC_TOKEN_ID= |
| 100 | +- Designed for Arc testnet only |
| 101 | +- Requires valid Circle API credentials and Supabase configuration |
| 102 | +- Admin wallet must have sufficient USDC and gas fees |
| 103 | +- ngrok (or similar) required for local webhook testing |
71 | 104 |
|
72 | | -# Misc |
73 | | -ADMIN_EMAIL=admin@admin.com |
74 | | -``` |
| 105 | +## Scripts |
75 | 106 |
|
76 | | -| Variable | Scope | Purpose | |
77 | | -| ------------------------------------- | ----------- | ------------------------------------------------------------------------ | |
78 | | -| `NEXT_PUBLIC_SUPABASE_URL` | Public | Supabase project URL. | |
79 | | -| `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_OR_ANON_KEY` | Public | Supabase anonymous/public key. | |
80 | | -| `SUPABASE_SERVICE_ROLE_KEY` | Server-side | Service role for privileged writes (e.g., transaction inserts). | |
81 | | -| `CIRCLE_API_KEY` | Server-side | Used to fetch Circle webhook public keys for signature verification. | |
82 | | -| `CIRCLE_ENTITY_SECRET` | Server-side | Circle entity secret for wallet operations. | |
83 | | -| `CIRCLE_BLOCKCHAIN` | Server-side | Blockchain network identifier (e.g., "ARC-TESTNET"). | |
84 | | -| `CIRCLE_USDC_TOKEN_ID` | Server-side | USDC token ID for the specified blockchain. | |
85 | | -| `ADMIN_EMAIL` | Server-side | Admin user email address. | |
| 107 | +- `npm run dev`: Start Next.js development server with auto-reload |
| 108 | +- `npx supabase start`: Start local Supabase instance |
| 109 | +- `npx supabase migration up`: Apply database migrations |
| 110 | + |
| 111 | +## Security & Usage Model |
| 112 | + |
| 113 | +This sample application: |
| 114 | +- Assumes testnet usage only |
| 115 | +- Handles secrets via environment variables |
| 116 | +- Verifies webhook signatures for security |
| 117 | +- Is not intended for production use without modification |
| 118 | + |
| 119 | +See `SECURITY.md` for vulnerability reporting guidelines. Please report issues privately via Circle's bug bounty program. |
0 commit comments