solpay/README.md
2025-08-14 10:41:04 +08:00

94 lines
2.1 KiB
Markdown

# SolPay API
A Node.js TypeScript application for handling Solana transactions.
## Setup
### 1. Install Dependencies
```bash
npm install mysql2
```
### 2. Environment Variables
Create a `.env` file in the root directory with the following variables:
```env
# Server Configuration
PORT=3000
NODE_ENV=development
LOG_LEVEL=info
# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password_here
DB_NAME=solpay
```
### 3. Database Setup
Make sure your MySQL database is running and the `solpay` database exists with the `transactions` table.
## API Endpoints
### Create New Transaction
- **URL**: `GET /tx/new`
- **Method**: `GET`
- **Query Parameters**:
- `tx` (required): Transaction hash
- `target_address` (required): Target wallet address
- `amount` (required): Transaction amount
- `token_mint` (required): Token mint address
- `token_program` (required): Token program address
- `validated_at` (required): Validation timestamp
- `sender_address` (required): Sender wallet address
- `metadata` (optional): Additional metadata
### Example Usage
```bash
curl "http://localhost:3000/tx/new?tx=abc123&target_address=target123&amount=1.5&token_mint=mint123&token_program=program123&validated_at=2024-01-01T00:00:00Z&sender_address=sender123&metadata=test"
```
### Get All Transactions
- **URL**: `GET /tx`
- **Method**: `GET`
### Get Transaction by Hash
- **URL**: `GET /tx/:txHash`
- **Method**: `GET`
## Running the Application
```bash
# Development
npm run dev
# Build and run
npm run build
npm start
```
## Database Schema
The `transactions` table should have the following structure:
```sql
CREATE TABLE transactions (
id INT AUTO_INCREMENT PRIMARY KEY,
tx VARCHAR(255) NOT NULL,
target_address VARCHAR(255) NOT NULL,
amount VARCHAR(255) NOT NULL,
token_mint VARCHAR(255) NOT NULL,
token_program VARCHAR(255) NOT NULL,
validated_at VARCHAR(255) NOT NULL,
sender_address VARCHAR(255) NOT NULL,
metadata TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
```