Platform: π Sage Realms - The first Starknet-native guild management platform with ZK-powered privacy
Discord Bot: β Production Ready - TypeScript Discord bot for BitSage Network
Webapp: ποΈ In Development - Next.js 14 guild management dashboard
Sage Realms is a comprehensive platform combining:
- Discord Bot - Real-time network stats, wallet integration, token-gating, and bot protection
- Web Dashboard - Guild management, analytics, reward campaigns, and subscription billing
Built for the BitSage Network on Starknet with privacy-preserving verification.
This is a monorepo containing both the Discord bot and webapp:
Sage-Discord/
βββ src/ # Discord bot source code
β βββ commands/ # Slash commands (15+ commands)
β βββ events/ # Discord event handlers
β βββ token-gating/ # Token-gating module (3,500+ lines)
β βββ bot-protection/ # Bot protection module (2,775+ lines)
β βββ services/ # Core services
β βββ utils/ # Utilities
β
βββ webapp/ # Next.js 14 webapp (NEW!)
β βββ app/ # Next.js App Router
β β βββ (marketing)/ # Public pages
β β βββ dashboard/ # Authenticated dashboard
β β βββ api/ # API routes
β β βββ login/ # Authentication
β βββ components/ # React components
β βββ lib/ # Utilities (auth, db, starknet)
β βββ public/ # Static assets
β
βββ migrations/ # Shared database migrations
β βββ 001-006_*.sql # Discord bot migrations
β βββ 007_webapp_guilds.sql # Webapp migrations
β
βββ dist/ # Compiled Discord bot
βββ package.json # Discord bot dependencies
βββ tsconfig.json # Discord bot TypeScript config
βββ README.md # This file
Shared Infrastructure:
- Same PostgreSQL database
- Same Starknet contracts (37 deployed on Sepolia)
- Shared types and migrations
/stats- View BitSage Network statistics (workers, jobs, proofs)/workers [address]- View active workers or get specific worker info/jobs [job_id] [limit]- View recent jobs or get specific job details/wallet <address>- Check wallet/validator information (stake, reputation, earnings)/rewards <address>- View pending and claimed rewards/ping- Check bot and API status
- Job Notifications: Real-time alerts when jobs are completed
- Network Stats Updates: Periodic network health updates
- API Integration: Direct connection to BitSage coordinator API
- Language: TypeScript 5.7+
- Framework: discord.js 14.x
- Runtime: Node.js 18+
- Database: PostgreSQL (shared with BitSage coordinator)
- API: BitSage Rust coordinator API integration
- Logging: Winston
- Node.js 18 or higher
- Discord Application with bot token
- BitSage coordinator running (default:
http://localhost:8080)
-
Clone the repository:
cd /Users/vaamx/bitsage-network/Sage-Discord -
Install dependencies:
npm install
-
Configure environment:
cp .env.example .env
Edit
.envand update the following:# Required DISCORD_BOT_TOKEN=your-bot-token-here DISCORD_APPLICATION_ID=1427094291226038302 DISCORD_CLIENT_ID=1427094291226038302 GUILD_ID=your-server-id-here # BitSage API BITSAGE_API_URL=http://localhost:8080 # Optional: Enable notifications JOB_NOTIFICATION_CHANNEL_ID=your-channel-id NETWORK_STATS_CHANNEL_ID=your-channel-id
-
Build the bot:
npm run build
-
Deploy slash commands:
npm run deploy-commands
-
Start the bot:
npm start
Or for development with auto-reload:
npm run dev
- Go to Discord Developer Portal
- Click "New Application" or use existing Application ID:
1427094291226038302 - Give it a name (e.g., "Sage Bot")
- Navigate to the "Bot" tab
- Click "Add Bot"
- Click "Reset Token" to get your bot token
- Important: Copy this token to
.envasDISCORD_BOT_TOKEN
Required bot permissions:
applications.commands(for slash commands)botscope- Permissions integer:
277025770496
Specific permissions:
- Send Messages
- Embed Links
- Read Message History
- Use Slash Commands
- Go to OAuth2 β URL Generator
- Select scopes:
bot,applications.commands - Select permissions above
- Copy the generated URL
- Open URL in browser and invite to your server
- Get your server ID (enable Developer Mode in Discord, right-click server β Copy Server ID)
- Add server ID to
.envasGUILD_ID
/stats
Shows network-wide stats including active workers, jobs, and proofs generated.
/workers
Lists all active workers with reputation scores.
/workers 0x0759a4374389b0e3cfcc59d49310b6bc75bb12bbf8ce550eb5c2f026918bb344
Get detailed information about a specific worker.
/jobs
Shows 10 most recent jobs.
/jobs limit:25
Shows 25 most recent jobs.
/jobs job_id:abc123...
Get details about a specific job.
/wallet address:0x0759a4374389b0e3cfcc59d49310b6bc75bb12bbf8ce550eb5c2f026918bb344
View stake, reputation, and earnings for a wallet.
/rewards address:0x0759a4374389b0e3cfcc59d49310b6bc75bb12bbf8ce550eb5c2f026918bb344
View pending and claimed rewards.
/ping
Check bot latency and API status.
Configure a channel to receive job completion notifications:
- Create a dedicated channel (e.g.,
#job-notifications) - Get the channel ID (right-click channel β Copy Channel ID)
- Add to
.env:JOB_NOTIFICATION_CHANNEL_ID=123456789012345678 ENABLE_JOB_NOTIFICATIONS=true JOB_POLL_INTERVAL=5 # Check every 5 minutes
The bot will post messages like:
β
Job Completed
Job ID: `abc123...`
Type: ZK Proof Generation
Worker: `0x0759a4...bb344`
Payment: 1000000000000000000 wei
Configure a channel for periodic network updates:
- Create a channel (e.g.,
#network-stats) - Get the channel ID
- Add to
.env:NETWORK_STATS_CHANNEL_ID=123456789012345678 ENABLE_NETWORK_STATS=true NETWORK_STATS_UPDATE_INTERVAL=30 # Post every 30 minutes
Sage-Discord/
βββ src/
β βββ commands/ # Slash command implementations
β β βββ stats.ts # /stats command
β β βββ workers.ts # /workers command
β β βββ jobs.ts # /jobs command
β β βββ wallet.ts # /wallet command
β β βββ rewards.ts # /rewards command
β β βββ ping.ts # /ping command
β βββ types/
β β βββ index.ts # TypeScript types and interfaces
β βββ utils/
β β βββ api-client.ts # BitSage API client
β β βββ config.ts # Environment config loader
β β βββ formatters.ts # Display formatting utilities
β β βββ logger.ts # Winston logging setup
β βββ index.ts # Main bot entry point
β βββ deploy-commands.ts # Slash command registration
βββ .env.example # Environment template
βββ package.json
βββ tsconfig.json
βββ README.md
- Check bot is online in Discord
- Verify commands were deployed:
npm run deploy-commands - Check logs for errors:
tail -f logs/combined.log - Ensure bot has proper permissions in Discord server
- Ensure BitSage coordinator is running at
BITSAGE_API_URL - Test API:
curl http://localhost:8080/health - Check coordinator logs for errors
- Run
npm run deploy-commandsagain - If using
GLOBAL_COMMANDS=true, wait up to 1 hour for propagation - If using
GUILD_ID, verify the ID is correct
- Copy
.env.exampleto.env - Fill in all required variables
- Restart the bot
Logs are stored in the logs/ directory:
combined.log- All logserror.log- Errors only
View live logs:
tail -f logs/combined.logSet LOG_LEVEL in .env:
error- Errors onlywarn- Warnings and errorsinfo- General information (default)debug- Detailed debugging
npm run devAuto-reloads on file changes.
npm run lintnpm run formatnpm run buildCompiles TypeScript to JavaScript in dist/ directory.
-
Install PM2:
npm install -g pm2
-
Build the bot:
npm run build
-
Start with PM2:
pm2 start dist/index.js --name sage-bot pm2 save pm2 startup
-
Monitor:
pm2 logs sage-bot pm2 monit
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
RUN npm run build
CMD ["npm", "start"]Build and run:
docker build -t sage-bot .
docker run -d --env-file .env --name sage-bot sage-bot- rust-node - Core node implementation
- BitSage-Cairo-Smart-Contracts - Smart contracts
- BitSage-WebApp - Web interface
MIT License - See LICENSE file for details
This repository is currently a placeholder. Check back soon for updates!
For general BitSage contributions, see CONTRIBUTING.md
Join our Discord: discord.gg/QAXDpa7F5K
Website: bitsage.network