# Compile contracts
bunx hardhat compile
# Start node
bunx hardhat node --verbose
# Deploy script
bunx hardhat run scripts/hardhat_deploy.js --network localhostDeploy BuildBear during testing switch ENV variables on front and backend to point to contracts on buildbear
bunx hardhat run scripts/buildbear_deploy.js --network buildbearMainnet requires security audit Deployer account should have multi-sig wallet Update hardhat.config.js for mainnet Integration test suite should be run against testnet Ensure all contract addresses on Mainnet are appropriately set as environment variables, and a separate wallet is used for the platform, consider setting another wallet address for the treasury.
Deploy on mainnet
bunx hardhat run scripts/mainnet_deploy.js --network mainnetChecklist:
✅ Environment variables for mainnet set locally?
✅ Hardhat mainnet network configured correctly?
✅ Testnet dry run completed successfully?
✅ Sufficient ETH in deployer account?
✅ Run mainnet_deploy.js script?
✅ Copy new contract addresses?
✅ Update backend environment variables?
✅ Update frontend environment variables and rebuild?
✅ Deploy updated backend to Render?
✅ Test the live application on mainnet (small test deposit)?
Once all updates have been made after deployment scripts run, add all production environment variables to env.production.local and update prod env variables
# Generate migration file
bunx drizzle-kit generate
# Apply to DB
bunx drizzle-kit migrateSimple:
# Build locally by running install script on backend and frontend locally then deploy to production environment
bun install
bun startAdvanced:
docker-compose up --buildUser Frontend Backend Services Database Ethereum Network
| | | | |
|--- Register -------------| | | |
| |--- POST /register ------->| | |
| | |--- DatabaseUtils.createUser() -->| |
| | | (creates user + balance)| |
|<-- Deposit Address ------| | | |
| | | | |
|--- Send xUSD ----------->| | | |
| | | |--- Ethereum tx -------->|
| | |<-- EVMService: deposit event| |
| | | (listens for Transfer) | |
| |<-- Balance Update --------|--- DatabaseUtils.updateBalanceWithTransaction() -> |
| | | (type: 'deposit') | |
| | | | |
|--- View Market --------->| | | |
| |--- GET /market/:id ------>| | |
| | |--- PredictionMarketService.getMarket() --> |
| | | (calls DatabaseUtils.getMarket()) |
|<-- Market Data ----------| | | |
| | | | |
|--- Get Quote ----------->| | | |
| | POST /market/prices/:id ->| | |
| | |--- PredictionMarketService.getMarketPrices() |
| | | (uses LMSR calculator) | |
|<-- Trade Quote ----------| | | |
| | | | |
|--- Place Bet ----------->| | | |
| | POST /market/buy/ ------->| | |
| | |--- PredictionMarketService.buyShares()| |
| | | (within DB transaction) | |
| | | ├─ check balance ------->| |
| | | ├─ calculate cost (LMSR) | |
| | | ├─ update inventory ---->| |
| | | ├─ update position ----->| |
| | | ├─ record transaction -->| |
| | | └─ emit 'sharesBought' | |
|<-- Trade Confirmed ------| | | |
| |<-- WebSocket Update ------| | |
| | | | |
|--- Wait for Outcome ---- | | | |
| | | | |
| |<-- Admin Resolves ------- |--- PredictionMarketService.resolveMarket() ->| |
| | | (sets resolved_outcome) | |
| | | | |
| |<-- Admin Triggers Payouts |--- PredictionMarketService.processPayouts() ->| |
| | | (within DB transaction) | |
| | | ├─ fetch winning positions| |
| | | ├─ update balances ----->| |
| | | ├─ mark claimed -------->| |
| | | └─ emit 'payoutsProcessed'| |
|<-- Payout Notification --| | | |
| | | | |
|--- Withdraw ------------>| | | |
| |--- POST /withdraw ------->| | |
| | |--- EVMService.requestWithdrawal()| |
| | | ├─ check balance ------->| |
| | | ├─ create withdrawal --->| |
| | | ├─ EVMService.sendTransaction() |--- Ethereum tx ->|
| | | └─ update withdrawal --->| |
|<-- Withdrawal Complete --| | | |