Create, trade, and manage tokens on the Γ¦ternity blockchain with advanced features and multi-level affiliation system.
- Project Overview
- Related Components
- Project Architecture
- System Requirements
- Quick Start with Docker
- Manual Installation
- Environment Configuration
- Available Scripts
- Docker Services
- Token Categories Configuration
- Development
- Contributing Guide
- Production Deployment
- Contributing
- License
This API serves as a caching and synchronization layer for the Bonding Curve Community platform on the Aeternity blockchain. It provides real-time token data, pricing information, and transaction history while maintaining collection-specific validation rules.
- bctsl/bctsl-sdk - SDK for interacting with the bonding curve contracts
- bctsl/bctsl-contracts - Smart contracts for the bonding curve token sale platform
- bctsl/bcl - Frontend application for the Bonding Curve Community platform
- π Multi-Collection Support: Handle multiple token collections with unique naming conventions and validation rules
- β‘ Real-time Pricing: Synchronize and cache token pricing from the bonding curve contracts
- π Transaction Tracking: Monitor and validate buy/sell transactions
- π Data Rankings: Provide token rankings globally and per collection
- π WebSocket Events: Broadcast real-time updates for token prices, creation, and transactions
- π§Ή Data Reorganization: Automatically handle and remove invalid transactions
- π MDW Integration: Seamless integration with Aeternity Middleware (MDW)
src/
βββ ae/ # Aeternity blockchain integration
βββ ae-pricing/ # Pricing calculation and synchronization
βββ configs/ # Application configuration
βββ tokens/ # Token management and WebSocket events
βββ transactions/ # Transaction processing and validation
βββ utils/ # Utility functions and helpers
-
π« Token Management (
src/tokens/)- Token data caching and retrieval
- WebSocket gateway for real-time updates
- Collection-specific validation rules
- Token ranking calculations
- Price history tracking
-
π± Transaction Processing (
src/transactions/)- Transaction monitoring and validation
- Buy/Sell operation tracking
- Invalid transaction handling
- Transaction history management
-
β Aeternity Integration (
src/ae/)- MDW client implementation
- Blockchain event monitoring
- Contract interaction
- Network synchronization
-
π° Pricing Engine (
src/ae-pricing/)- Price synchronization
-
π¦ Initialization
- Load collection configurations
- Establish MDW connection
- Initialize WebSocket server
- Start price synchronization
-
π« Token Operations
- Validate token names against collection rules
- Calculate and cache token prices
- Track token ownership
- Update token rankings
- Broadcast token events
-
πΈ Transaction Handling
- Monitor blockchain for new transactions
- Validate transaction legitimacy
- Update token prices and ownership
- Broadcast transaction events
- Handle transaction reorganization
-
π Data Synchronization
- Periodic price updates
- Transaction history synchronization
- Data cleanup and validation
- Cache management
-
π« Token Endpoints
- Token validation
- Price history retrieval
- Token rankings (global/collection)
-
π± Transaction Endpoints
- Transaction history
- Transaction validation status
-
π WebSocket Events
- Token price updates
- New token creation
- Transaction notifications
- Collection updates
- Web in-app notification feed (live
notification/unread-counton the/notificationsnamespace) + native browser push (Web Push / VAPID) for closed-tab delivery β see docs/notifications-web-feed.md- Enabling browser push: run
npx web-push generate-vapid-keysand add the pair asVAPID_PUBLIC_KEY/VAPID_PRIVATE_KEYsecrets on each GitHub environment. Check withcurl <api>/api/notifications/web-push/vapid-public-key: apublicKeystring means push is on,nullmeans it is off. Boot refuses a public key that is not the private key's pair.
- Enabling browser push: run
-
π Collection Management
- Collection configuration
- Validation rules
- Naming conventions
- Character code restrictions
The API implements a multi-layer caching strategy:
-
π‘ In-Memory Cache
- Active token prices
- Recent transactions
- Validation rules
-
β‘ Redis Cache
- Token rankings
- Price history
- Collection statistics
-
π½ PostgreSQL Database
- Historical data
- Transaction records
- Token metadata
- Collection configurations
- π¦ Node.js >= 18
- ποΈ PostgreSQL >= 16
- π Redis (latest)
- π³ Docker and Docker Compose (for containerized setup)
The easiest way to run the application is using Docker Compose:
# Clone the repository
git clone https://github.com/bctsl/bctsl-api.git
cd bctsl-api
# Setup environment variables
cp .env.example .env
# Start all services
docker compose up --buildThe application will be available at http://localhost:3000.
For a Shorts-enabled deployment, build the API from a clean Git checkout and keep local upload state and keys outside the build context. Deploy the media services from superhero-shorts.
If you prefer to run the services locally:
# Install dependencies
npm install
# Setup environment variables
cp .env.example .env
# Start the development server
npm run start:devConfigure the following environment variables in your .env file:
# Database Configuration
DB_TYPE=postgres
DB_HOST=127.0.0.1 # Use 'postgres' if running with Docker
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres # Change in production
DB_DATABASE=bcl_api
DB_SYNC=true # Set to false in production
# Redis Configuration
REDIS_HOST=localhost # Use 'redis' if running with Docker
REDIS_PORT=6379
# Network Configuration
AE_NETWORK_ID=ae_mainnet # or ae_uat for testnet
# Application Configuration
APP_PORT=3000# Development
npm run start # Start the application
npm run start:dev # Start with hot-reload
npm run start:prod # Start in production modeThe project includes three main services:
-
API Service (
api):- NestJS application
- Runs on port 3000
- Auto-reloads in development
-
PostgreSQL (
postgres):- Version 16
- Persists data in a Docker volume
- Accessible on port 5432
-
Redis (
redis):- Latest Alpine version
- Persists data in a Docker volume
- Accessible on port 6379
Define the collections you want the API to support in src/configs/contracts.ts:
export const BCL_FACTORY: Record<INetworkTypes, ICommunityFactorySchema> = {
[NETWORK_ID_MAINNET]: {
address: 'ct_..',
collections: {
// Example configuration:
// 'CATEGORY-ak_..': {
// name: 'CATEGORY',
// allowed_name_length: '20',
// description: 'Tokenize a unique name with up to 20 characters',
// },
},
},
[NETWORK_ID_TESTNET]: {
address: 'ct_..',
collections: {}
}
};For detailed information about our development standards, testing practices, and contribution guidelines, please see our Contributing Guide.
# Start all services
docker compose up
# Start services in background
docker compose up -d
# Stop all services
docker compose down
# View logs
docker compose logs -f
# Rebuild services
docker compose up --buildTo run another testnet instance in Docker with its own database and Redis (e.g. for a separate test environment):
# Optional: set env for DB credentials and ports (defaults: user testnet, DB api_testnet2, API port 3001, Postgres 5437, Redis 6380)
export TESTNET_DB_USER=testnet
export TESTNET_DB_PASSWORD=testnet
export TESTNET_DB_DATABASE=api_testnet2
export TESTNET_APP_PORT=3001
export TESTNET_DB_PORT=5437
export TESTNET_REDIS_PORT=6380
# Start the second testnet stack
docker compose -f docker-compose-testnet.yml up -d
# API: http://localhost:3001 (or TESTNET_APP_PORT)
# Stop: docker compose -f docker-compose-testnet.yml downThe stack uses AE_NETWORK_ID=ae_uat, separate volumes (postgres_testnet2_data, redis_testnet2_data), and container names superhero-api-testnet2, superhero-api-testnet2-db, superhero-api-testnet2-redis so it does not conflict with the default compose or another testnet deploy.
If you run the app on the host (npm run start:prod) it uses your .env (e.g. DB_HOST=127.0.0.1, DB_PORT=5436). That points at your local/dev DB and Redis, not the testnet containersβso you get ECONNREFUSED if nothing is listening on those ports. Either use the API in Docker at http://localhost:3001, or run the app on the host against the testnet DB/Redis by copying .env.testnet.example to .env (it uses DB_PORT=5437, REDIS_PORT=6380 and user testnet/DB api_testnet2 to match the testnet stack).
The database automatically syncs schema changes in development (DB_SYNC=true). For production, you should manage database migrations manually.
For production deployment:
- Set appropriate environment variables
- Run
node scripts/migrate-with-lock.jsas a deployment job with migration credentials - Disable
DB_SYNC - Use proper secrets management
- Configure proper network settings
- Enable SSL/TLS
Use the same release image for the migration job and API. Wait for the job to
succeed, then start the API with node dist/main and its restricted runtime
database credentials. The image's default command combines migration and startup;
override it when the two roles are separate. Do not give the running API schema
ownership or CREATE permissions just to run migrations.
Apply 1791849600000-ProductionRuntimeSchema before this runtime. It moves the
legacy token eligibility tables and DEX schema additions into migrations.
Production startup checks required columns without executing DDL. Existing data
is preserved, including when reverting the migration. Missing indexes are built
in the migration transaction; allow for its locks when scheduling an upgrade on
large tables. Production GraphQL builds its schema in memory, so the application
filesystem can be read-only.
We welcome contributions! Please see our Contributing Guide for details on:
- Development standards
- Code style and linting
- Testing requirements
- Commit message conventions
- Pull request process
This project is licensed under the ISC License - see the LICENSE file for details.
Copyright (c) 2025, BCTSL