This guide will help you set up and run the Vesting Vault backend with the new historical price tracking feature.
- Node.js (v16 or higher)
- PostgreSQL (v15 or higher)
- Git
Install and start PostgreSQL:
# On Windows (using Chocolatey)
choco install postgresql15
# On macOS (using Homebrew)
brew install postgresql@15
brew services start postgresql@15
# On Ubuntu/Debian
sudo apt update
sudo apt install postgresql-15
sudo systemctl start postgresqlCreate the database:
# Connect to PostgreSQL
psql -U postgres
# Create database
CREATE DATABASE vesting_vault;
# Create user (optional, if not using default postgres user)
CREATE USER vesting_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE vesting_vault TO vesting_user;# Navigate to backend directory
cd backend
# Install dependencies
npm install
# Copy environment file
cp .env.example .env
# Edit .env file with your database configurationEdit backend/.env:
NODE_ENV=development
PORT=3000
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=vesting_vault
DB_USER=postgres
DB_PASSWORD=password
# Optional: CoinGecko API (for higher rate limits)
COINGECKO_API_KEY=your_api_key_here
# Stellar Network Configuration
STELLAR_RPC_URL=https://soroban-testnet.stellar.org
STELLAR_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"# Development mode (with auto-restart)
npm run dev
# Production mode
npm startThe application will be available at http://localhost:3000
curl http://localhost:3000/health# Run the comprehensive test suite
node test/historicalPriceTracking.test.jscurl -X POST http://localhost:3000/api/claims \
-H "Content-Type: application/json" \
-d '{
"user_address": "0x1234567890123456789012345678901234567890",
"token_address": "0xA0b86a33E6441e6c8d0A1c9c8c8d8d8d8d8d8d8d",
"amount_claimed": "100.5",
"claim_timestamp": "2024-01-15T10:30:00Z",
"transaction_hash": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
"block_number": 18500000
}'curl "http://localhost:3000/api/claims/0x1234567890123456789012345678901234567890/realized-gains"- Ensure PostgreSQL is running
- Check database credentials in
.env - Verify database exists:
psql -U postgres -l
- The CoinGecko API has rate limits
- Consider getting a CoinGecko API key for higher limits
- The implementation includes caching to minimize API calls
- Change PORT in
.envif 3000 is already in use - Ensure no other application is using the same port
- Make your changes to the code
- Run tests to verify functionality
- Commit changes with descriptive messages
- Push to your feature branch
- Create a pull request
# Run all tests
npm test
# Run specific test file
node test/historicalPriceTracking.test.jsThe application uses Sequelize sync() for development. For production:
- Consider using proper migrations
- Backup database before schema changes
See HISTORICAL_PRICE_TRACKING.md for detailed API documentation and usage examples.
For production deployment:
- Use environment variables for all configuration
- Enable proper logging
- Set up database connection pooling
- Configure reverse proxy (nginx)
- Set up monitoring and alerting
- Use proper SSL certificates
If you encounter issues:
- Check the logs for error messages
- Verify all prerequisites are installed
- Ensure database is running and accessible
- Check network connectivity for external API calls