|
| 1 | +# 2wp-API Startup Guide |
| 2 | + |
| 3 | +This guide provides step-by-step instructions to start the 2wp-API application, ensuring all required services are properly configured and running. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before starting the API, ensure you have the following installed: |
| 8 | +- **Node.js** (version 18.17.0 as specified in `.nvmrc`) |
| 9 | +- **npm** (comes with Node.js) |
| 10 | +- **Docker** and **Docker Compose** (for running required databases) |
| 11 | +- **nvm** (Node Version Manager) - recommended for managing Node.js versions |
| 12 | + |
| 13 | +## Step 1: Verify Node.js and npm Versions |
| 14 | + |
| 15 | +First, ensure you're using the correct Node.js version: |
| 16 | + |
| 17 | +```bash |
| 18 | +# Check if nvm is available |
| 19 | +nvm --version |
| 20 | + |
| 21 | +# Use the correct Node.js version (18.17.0) |
| 22 | +nvm use |
| 23 | + |
| 24 | +# Verify the version |
| 25 | +node --version |
| 26 | +npm --version |
| 27 | +``` |
| 28 | + |
| 29 | +**Expected output:** |
| 30 | +- Node.js: v18.17.0 |
| 31 | +- npm: Should be compatible with Node.js 18.17.0 |
| 32 | + |
| 33 | +## Step 2: Install Dependencies |
| 34 | + |
| 35 | +Install all required npm packages: |
| 36 | + |
| 37 | +```bash |
| 38 | +# Install dependencies from package-lock.json |
| 39 | +npm ci |
| 40 | +``` |
| 41 | + |
| 42 | +## Step 3: Environment Configuration |
| 43 | + |
| 44 | +Create a `.env` file in the root directory with the required environment variables. You can use the example from `ENV_VARIABLES.md` as a template: |
| 45 | + |
| 46 | +```bash |
| 47 | +# Copy the example environment file (if available) |
| 48 | +cp .env.test .env |
| 49 | + |
| 50 | +# Or create a new .env file manually |
| 51 | +touch .env |
| 52 | +``` |
| 53 | + |
| 54 | +**Required environment variables for basic operation:** |
| 55 | +```dotenv |
| 56 | +NETWORK='testnet' |
| 57 | +BTC_CONFIRMATIONS=100 |
| 58 | +RSK_PEGOUT_MINIMUM_CONFIRMATIONS=10 |
| 59 | +BLOCKBOOK_URL='https://your-blockbook-url' |
| 60 | +MAX_AMOUNT_ALLOWED_IN_SATOSHI=100000000 |
| 61 | +
|
| 62 | +# SessionDB (Redis) Configuration |
| 63 | +SESSIONDB_HOST='localhost' |
| 64 | +SESSIONDB_PORT=6379 |
| 65 | +SESSIONDB_PASSWORD='sessiondb-2wp-api-password' |
| 66 | +SESSIONDB_INDEX=1 |
| 67 | +
|
| 68 | +# Federation Addresses history |
| 69 | +FEDERATION_ADDRESSES_HISTORY='2N6JWYUb6Li4Kux6UB2eihT7n3rm3YX97uv 2N1y7hSneV9HuWnpLTtGqdRnway1Ag3dQoj 2NF9ndVaez5owUShjSxNnY2E31QkRjLu63k 2N5exbrgeGBuKXqcinfz68atduq6ApHN4b4 2Mu7ayegt8AYi7vGYtG2KGaXErPWBQhPVfu 2N1rW3cBZNzs2ZxSfyNW7cMcNBktt6fzs88 2N1GMB8gxHYR5HLPSRgf9CJ9Lunjb9CTnKB' |
| 70 | +
|
| 71 | +# DAEMON SYNC - https://explorer.testnet.rsk.co/block/2019830 |
| 72 | +SYNC_INITIAL_BLOCK_HEIGHT=2019830 |
| 73 | +SYNC_INITIAL_BLOCK_HASH='0xf5d6a4b3df6311f5852de936142e669e7fba12c8476dc22d8a9c88267e78aee3' |
| 74 | +SYNC_INITIAL_BLOCK_PREV_HASH='0x4e2ac28a61452e911d6f598679abb5ccf8c7988e773e30bfa0891a4e722a2961' |
| 75 | +SYNC_MIN_DEPTH=6 |
| 76 | +SYNC_INTERVAL_TIME=2000 |
| 77 | +
|
| 78 | +# MongoDB Configuration |
| 79 | +RSK_DB_CONNECTION_USER='api-user' |
| 80 | +RSK_DB_CONNECTION_PASSWORD='api-pwd' |
| 81 | +RSK_DB_CONNECTION_HOST='localhost' |
| 82 | +RSK_DB_CONNECTION_PORT='27017' |
| 83 | +RSK_DB_CONNECTION_DATABASE='rsk' |
| 84 | +RSK_DB_CONNECTION_AUTH_SOURCE='rsk' |
| 85 | +
|
| 86 | +#FeePerKB (Sat/b) |
| 87 | +FEE_PER_KB_FAST_MIN=100 |
| 88 | +FEE_PER_KB_AVERAGE_MIN=100 |
| 89 | +FEE_PER_KB_SLOW_MIN=100 |
| 90 | +MAX_FEE_AMOUNT_ALLOWED=5000000 |
| 91 | +
|
| 92 | +#Dust value (Satoshi) |
| 93 | +BURN_DUST_VALUE=2000 |
| 94 | +
|
| 95 | +NODE_ENV=development |
| 96 | +``` |
| 97 | + |
| 98 | +## Step 4: Start SessionDB (Redis) |
| 99 | + |
| 100 | +The SessionDB is required for the API to function properly. Start it using Docker: |
| 101 | + |
| 102 | +```bash |
| 103 | +# Navigate to SessionDB directory |
| 104 | +cd SessionDB |
| 105 | + |
| 106 | +# Start Redis container |
| 107 | +docker-compose up -d |
| 108 | + |
| 109 | +# Verify the container is running |
| 110 | +docker-compose ps |
| 111 | + |
| 112 | +# Return to root directory |
| 113 | +cd .. |
| 114 | +``` |
| 115 | + |
| 116 | +**Expected output:** Redis container should be running on port 6379. |
| 117 | + |
| 118 | +## Step 5: Start RSK Database (MongoDB) |
| 119 | + |
| 120 | +The RSK database must be running before starting the API. Follow these steps: |
| 121 | + |
| 122 | +```bash |
| 123 | +# Navigate to rsk-database directory |
| 124 | +cd rsk-database |
| 125 | + |
| 126 | +# Copy your .env file to this directory (required for docker-compose) |
| 127 | +cp ../.env . |
| 128 | + |
| 129 | +# Start MongoDB container |
| 130 | +docker-compose up -d |
| 131 | + |
| 132 | +# Verify the container is running |
| 133 | +docker-compose ps |
| 134 | + |
| 135 | +# Return to root directory |
| 136 | +cd .. |
| 137 | +``` |
| 138 | + |
| 139 | +**Expected output:** MongoDB container should be running on port 27017. |
| 140 | + |
| 141 | +## Step 6: Create MongoDB User (First Time Only) |
| 142 | + |
| 143 | +If this is your first time setting up the database, you need to create a user with admin permissions: |
| 144 | + |
| 145 | +```bash |
| 146 | +# Access the MongoDB container |
| 147 | +docker exec -it 2wp-rsk-mongo-database bash |
| 148 | + |
| 149 | +# Connect to MongoDB shell |
| 150 | +mongosh |
| 151 | + |
| 152 | +# Switch to rsk database |
| 153 | +use rsk |
| 154 | + |
| 155 | +# Create admin user |
| 156 | +db.createUser( |
| 157 | + { |
| 158 | + user: "api-user", |
| 159 | + pwd: "api-pwd", |
| 160 | + roles: [ |
| 161 | + { role: "userAdmin", db:"rsk" } |
| 162 | + ] |
| 163 | + } |
| 164 | +) |
| 165 | + |
| 166 | +# Exit MongoDB shell |
| 167 | +exit |
| 168 | + |
| 169 | +# Exit container |
| 170 | +exit |
| 171 | +``` |
| 172 | +
|
| 173 | +## Step 7: Build the Application |
| 174 | +
|
| 175 | +Before starting the API, build the TypeScript application: |
| 176 | +
|
| 177 | +```bash |
| 178 | +# Build the application |
| 179 | +npm run build |
| 180 | +``` |
| 181 | +
|
| 182 | +## Step 8: Start the API |
| 183 | +
|
| 184 | +Now you can start the API using the `start-api` command: |
| 185 | +
|
| 186 | +```bash |
| 187 | +# Start only the API (without daemon) |
| 188 | +npm run start-api |
| 189 | +``` |
| 190 | +
|
| 191 | +**Expected output:** The API should start and be accessible at `http://127.0.0.1:3000`. |
| 192 | +
|
| 193 | +## Step 9: Verify API is Running |
| 194 | +
|
| 195 | +Open your browser and navigate to: |
| 196 | +- **API Explorer:** http://127.0.0.1:3000/explorer |
| 197 | +- **API Root:** http://127.0.0.1:3000/ |
| 198 | +
|
| 199 | +You should see the API documentation and be able to test endpoints. |
| 200 | +
|
| 201 | +## Alternative Commands |
| 202 | +
|
| 203 | +### Start Both API and Daemon |
| 204 | +```bash |
| 205 | +npm start |
| 206 | +``` |
| 207 | +
|
| 208 | +### Start Only Daemon |
| 209 | +```bash |
| 210 | +npm run start-daemon |
| 211 | +``` |
| 212 | +
|
| 213 | +### Development Mode with Watch |
| 214 | +```bash |
| 215 | +npm run build:watch |
| 216 | +``` |
| 217 | +
|
| 218 | +## Stopping Services |
| 219 | +
|
| 220 | +To stop all services when you're done: |
| 221 | +
|
| 222 | +```bash |
| 223 | +# Stop API (Ctrl+C in the terminal where it's running) |
| 224 | +
|
| 225 | +# Stop MongoDB |
| 226 | +cd rsk-database |
| 227 | +docker-compose down |
| 228 | +cd .. |
| 229 | +
|
| 230 | +# Stop Redis |
| 231 | +cd SessionDB |
| 232 | +docker-compose down |
| 233 | +cd .. |
| 234 | +``` |
| 235 | + |
| 236 | +## Support |
| 237 | + |
| 238 | +If you encounter issues not covered in this guide: |
| 239 | +1. Review `ENV_VARIABLES.md` for environment variable details |
| 240 | +2. Check the application logs in the `log/` directory |
| 241 | +3. Verify all Docker containers are running properly |
0 commit comments