Skip to content

Integration

M1k3lee edited this page Nov 18, 2025 · 1 revision

Integration Story: Bringing It All Together

Written by MikeLee

This is the story of how we took individual components - smart contracts, backend services, frontend interfaces, and cross-chain infrastructure - and merged them into one cohesive platform. This was the hardest part of the project, but also the most rewarding.

The Challenge

By Week 24, we had:

  • ✅ Smart contracts deployed on 3 testnets
  • ✅ Backend API running locally
  • ✅ Frontend UI built
  • ✅ Cross-chain messaging working
  • ✅ Hedera integration complete

But they were all separate. The challenge was making them work together seamlessly.

Integration Phases

Phase 1: Smart Contracts ↔ Backend

Goal: Backend needs to track all on-chain activity.

Challenge: How do we know when something happens on-chain?

Solution: Event monitoring + polling

Implementation:

  1. Contracts emit events for all major actions
  2. Backend monitors events via RPC
  3. Backend stores data in database
  4. Frontend queries backend for data

Key Events:

  • TokenCreated - New token deployed
  • TokenBought - Buy transaction
  • TokenSold - Sell transaction
  • Graduated - Token graduated to DEX
  • SupplyUpdated - Global supply changed

Code Example:

// Backend monitors events
const filter = contract.filters.TokenBought();
contract.on(filter, async (buyer, amountPaid, tokensReceived, event) => {
  // Store transaction in database
  await db.run(
    'INSERT INTO transactions (token_id, chain, tx_hash, type, ...)',
    [tokenId, chain, event.transactionHash, 'buy', ...]
  );
});

Result: Backend now has real-time visibility into all on-chain activity.

Phase 2: Backend ↔ Frontend

Goal: Frontend needs real-time data from backend.

Challenge: How to keep frontend updated without constant polling?

Solution: React Query with smart polling + WebSocket (future)

Implementation:

  1. Frontend uses React Query for data fetching
  2. Queries refetch every 15 seconds
  3. Optimistic updates for user actions
  4. Error handling and retry logic

Key Endpoints:

  • GET /api/tokens/:id/status - Token status
  • GET /api/transactions - Transaction history
  • GET /api/tokens/:id/price-sync - Price sync status
  • POST /api/tokens - Create token (triggers on-chain)

Result: Frontend displays real-time data with minimal latency.

Phase 3: Cross-Chain Synchronization

Goal: Keep prices synchronized across all chains.

Challenge: Multiple chains, multiple contracts, one source of truth.

Solution: GlobalSupplyTracker + LayerZero + Backend Monitoring

Flow:

  1. User buys on Chain A
  2. BondingCurve updates local supply
  3. Calls GlobalSupplyTracker.updateSupply()
  4. GlobalSupplyTracker sends LayerZero message
  5. Chains B and C receive message
  6. Their GlobalSupplyTrackers update
  7. All BondingCurves see new global supply
  8. Prices update on all chains
  9. Backend monitors all chains
  10. Frontend shows synchronized prices

Implementation:

// BondingCurve.sol
function buy(uint256 tokenAmount) external payable {
    // ... buy logic ...
    
    // Update global supply
    globalSupplyTracker.updateSupply(
        address(token),
        chainName,
        totalSupplySold
    );
}
// GlobalSupplyTracker.sol
function updateSupply(...) external {
    // Update local state
    globalSupply[token] = newSupply;
    
    // Send to other chains
    if (crossChainEnabled) {
        crossChainSync.syncSupplyUpdate(token, newSupply, currentChainEID);
    }
}

Result: Prices stay synchronized within 0.5% variance across all chains.

Phase 4: Liquidity Bridge Integration

Goal: Automatic liquidity rebalancing across chains.

Challenge: Detecting low reserves and triggering bridging.

Solution: Backend monitoring service + Smart contract integration

Flow:

  1. Backend monitors reserves every 30 seconds
  2. Detects chain with low reserves
  3. Calls requestLiquidity() on bridge contract
  4. Bridge sends LayerZero message
  5. Chain with excess liquidity fulfills request
  6. Liquidity is transferred
  7. Reserves updated on both chains
  8. Backend confirms update

Implementation:

// Backend service
async function monitorLiquidity() {
  for (const chain of chains) {
    const reserves = await checkReserves(chain);
    if (reserves < threshold) {
      await bridge.requestLiquidity(token, chain, amount);
    }
  }
}

setInterval(monitorLiquidity, 30000); // Every 30 seconds

Result: All chains maintain optimal reserves automatically.

Phase 5: Hedera Integration

Goal: Immutable audit trails for all transactions.

Challenge: Integrating Hedera services with existing backend.

Solution: Hedera Audit Service as middleware

Flow:

  1. Transaction occurs on-chain
  2. Backend detects transaction
  3. Hedera Audit Service logs to HCS
  4. HCS creates immutable record
  5. Frontend displays audit trail

Implementation:

// Hedera Audit Service
async function logTransaction(tx) {
  const message = JSON.stringify({
    type: 'BONDING_CURVE_TX',
    tokenId: tx.tokenId,
    chain: tx.chain,
    txHash: tx.txHash,
    type: tx.type,
    amount: tx.amount,
    price: tx.price,
    timestamp: Date.now()
  });
  
  await hcsClient.submitMessage(topicId, message);
}

Result: All transactions have permanent, tamper-proof audit records.

Integration Challenges

Challenge 1: Event Ordering

Problem: Events from different chains arrive out of order.

Solution: Timestamp-based ordering + sequence numbers

Implementation:

  • Each event includes timestamp
  • Backend orders by timestamp
  • Sequence numbers for same-timestamp events

Challenge 2: Failed Cross-Chain Messages

Problem: LayerZero messages can fail.

Solution: Retry logic + fallback to local pricing

Implementation:

  • Retry failed messages up to 3 times
  • If all retries fail, use local pricing
  • Log failures for manual reconciliation
  • Alert system for persistent failures

Challenge 3: Database Consistency

Problem: Multiple chains, one database - how to keep consistent?

Solution: Chain-aware data model + transactions

Implementation:

  • All data includes chain identifier
  • Database transactions for multi-step operations
  • Unique constraints prevent duplicates
  • Regular consistency checks

Challenge 4: Frontend State Management

Problem: Complex state across multiple chains.

Solution: React Query + Context API

Implementation:

  • React Query for server state
  • Context for UI state
  • Optimistic updates
  • Error boundaries

Integration Testing

End-to-End Scenarios

Scenario 1: Token Creation

  1. User fills form in frontend
  2. Frontend calls backend API
  3. Backend deploys contracts on-chain
  4. Contracts emit events
  5. Backend stores in database
  6. Frontend refreshes and shows token
  7. ✅ All steps verified

Scenario 2: Cross-Chain Buy

  1. User buys on Chain A
  2. BondingCurve updates supply
  3. GlobalSupplyTracker syncs to Chains B & C
  4. Prices update on all chains
  5. Backend records transaction
  6. Hedera logs transaction
  7. Frontend shows updated prices
  8. ✅ Synchronization verified

Scenario 3: Liquidity Bridge

  1. Chain A runs low on reserves
  2. Backend detects and triggers bridge
  3. Bridge requests liquidity from Chain B
  4. Chain B sends liquidity
  5. Chain A receives and updates reserves
  6. Backend confirms update
  7. Frontend shows updated reserves
  8. ✅ Bridging verified

Performance Optimization

Database Optimization

Problem: Slow queries with many tokens/transactions.

Solution:

  • Added indexes on frequently queried fields
  • Optimized JOIN queries
  • Implemented pagination
  • Added caching layer

Result: Query time reduced from 2s to <100ms.

API Optimization

Problem: Too many API calls from frontend.

Solution:

  • Implemented request batching
  • Added response caching
  • Optimized database queries
  • Reduced polling frequency

Result: API calls reduced by 60%.

Frontend Optimization

Problem: Slow page loads and updates.

Solution:

  • Code splitting
  • Lazy loading
  • Optimistic updates
  • Memoization

Result: Page load time reduced by 40%.

Monitoring & Observability

What We Monitor

  1. Smart Contracts:

    • Event emissions
    • Gas usage
    • Error rates
  2. Backend:

    • API response times
    • Error rates
    • Database query performance
    • Service health
  3. Frontend:

    • Page load times
    • Error rates
    • User interactions
  4. Cross-Chain:

    • Message delivery rates
    • Price variance
    • Liquidity levels

Alerting

  • Price variance > 1%
  • Message delivery failures
  • API errors
  • Database issues
  • Low liquidity warnings

The Result

After weeks of integration work, we had a fully functional platform where:

  • ✅ Smart contracts work seamlessly together
  • ✅ Backend tracks all on-chain activity
  • ✅ Frontend displays real-time data
  • ✅ Cross-chain synchronization works
  • ✅ Liquidity bridging is automatic
  • ✅ Audit trails are immutable

Everything works together as one cohesive system.

Lessons Learned

What Worked Well

  1. Incremental Integration: Integrating one component at a time made debugging easier
  2. Comprehensive Testing: Testing each integration point caught issues early
  3. Clear Interfaces: Well-defined interfaces between components
  4. Documentation: Good documentation helped during integration

What Was Challenging

  1. State Synchronization: Keeping state consistent across components
  2. Error Handling: Handling errors across the stack
  3. Performance: Optimizing the entire system
  4. Debugging: Debugging issues across multiple components

What We'd Do Differently

  1. Integration Tests Earlier: Would have caught issues sooner
  2. Better Monitoring: More comprehensive monitoring from the start
  3. Documentation: More inline documentation during integration
  4. Performance Testing: More performance testing during integration

Conclusion

Integration was the hardest part of building Crossify, but also the most rewarding. Seeing all the pieces work together seamlessly was incredibly satisfying. The platform is now a cohesive system where every component works in harmony.

- MikeLee


For development process, see Development Process For testing details, see Testing For roadmap, see Roadmap