x402通知
通过x402协议进行区块链支付的通知系统,支持Solana和EVM测试网,与NotificationAPI.com和Turso数据库集成,并为AI助手提供MCP端点支持。

特性
- 多通道通知:通过NotificationAPI发送电子邮件、短信、推送、应用内、语音和Slack
- 区块链支付:支持Base、Base Sepolia、Solana Devnet、Solana Testnet的x402协议
- 边缘数据库:Turso(libSQL)用于快速、分布式数据存储
- MCP协议:AI助手可以以编程方式与系统交互
- 现代堆栈:Next.js 16,React 19,shadcn/ui,Bun运行时
先决条件
设置
- 安装依赖项:
bun install- 创建Turso数据库:
turso db create x402-notifications
turso db show x402-notifications- 配置环境变量:
cp .env.example .env
# Edit .env with your Turso credentials- 运行数据库迁移:
bun run scripts/01-create-schema.sql
bun run scripts/02-seed-data.sql- 启动开发服务器:
bun dev项目结构
├── app/
│ ├── api/
│ │ ├── notifications/ # Notification API routes
│ │ ├── payments/ # Payment tracking
│ │ ├── users/ # User management
│ │ ├── mcp/ # MCP protocol endpoint
│ │ └── x402/ # x402 webhook handler
│ ├── dashboard/ # Protected dashboard (x402)
│ └── page.tsx # Landing page
├── components/
│ ├── notification-card.tsx # Notification UI component
│ ├── payment-card.tsx # Payment UI component
│ └── stats-card.tsx # Stats dashboard card
├── lib/
│ ├── turso.ts # Database client & types
│ ├── notification-service.ts# NotificationAPI integration
│ ├── x402-payment-handler.ts# Payment processing
│ └── mcp-server.ts # MCP protocol handler
├── scripts/
│ ├── 01-create-schema.sql # Database schema
│ └── 02-seed-data.sql # Seed data
├── proxy.ts # Next.js 16 proxy (x402 payment gates)
└── bunfig.toml # Bun configurationMCP API
该系统在\/api/MCP\处为AI助手公开了一个MCP端点。可用方法:
- \
createSession \:创建身份验证会话 - \
sendNotification \:向用户发送通知 - \
getNotifications \:获取用户通知 - \
markNotificationRead\:将通知标记为已读 - \
getPaymentHistory \:获取付款交易记录 - \`getTotalSpend:计算总支出
- \
getUser\:获取用户配置文件
有关完整文档,请参阅\/api/mcp/docs\。
x402支付集成
受保护的路线需要小额支付:
- 仪表板:0.01美元
- 发送通知API:0.005美元
- 分析:0.02美元
支持Base Sepolia,可配置用于Solana测试网。
技术
- 运行时:Bun
- 框架:Next.js 16,带应用路由器
- 用户界面:shadcn/ui+顺风CSS v4+Lucide React
- 数据库:turso(libsql)
- 通知:通知
- 支付:x402下一个协议
- 类型:TypeScript
许可证
麻省理工学院
