Skip to main content

On-Chain vs Off-Chain

Beforehand uses a hybrid architecture that keeps critical financial operations on-chain while storing metadata and social features off-chain.

On-Chain (Smart Contracts)

What's On-Chain

  • Market contracts: Each market is a deployed smart contract
  • Position tokens: yUSDC (YES) and nUSDC (NO) ERC20 tokens
  • Pool tracking: YES and NO pool balances
  • Resolution logic: Market outcome and redemption
  • USDC collateral: All trading uses USDC as collateral

Why On-Chain

  • Security: Financial operations are immutable and verifiable
  • Trust: Users can verify market state independently
  • Decentralization: No single point of failure for funds
  • Transparency: All trades and resolutions are public

Off-Chain (Database)

What's Off-Chain

  • User profiles: Names, handles, avatars
  • Market metadata: Questions, descriptions, categories
  • Communities: Community data, memberships, permissions
  • Voting records: User votes and credibility scores
  • Social features: Comments, notifications, reports

Why Off-Chain

  • Flexibility: Easy to update metadata and social features
  • Performance: Fast queries and real-time updates
  • Cost: Avoids gas fees for non-financial operations
  • Rich features: Complex queries and relationships

Synchronization

The system keeps on-chain and off-chain data synchronized:

  • Market creation: Contract address stored in database
  • Trading: Database tracks positions from on-chain token balances
  • Resolution: Database updated when contract resolves
  • Real-time sync: Frontend queries both sources and merges data

Security Model

  • Critical operations (trades, resolution, payouts): On-chain only
  • Metadata updates: Off-chain with admin controls
  • Voting: Off-chain but affects on-chain resolution
  • Permissions: Hybrid (community ownership on-chain, membership off-chain)