Skip to main content

Build Escrow dApp

In this section, you’ll build a complete escrow dApp that allows users to:
  • Claim mock tokens (Mock Coin, Mock TBTC, Mock zSUI)
  • View token balances
  • Create, accept, and cancel escrow transactions

Overview

The escrow dApp consists of:
  1. Balance Display - Show all token balances
  2. Faucet Components - Claim mock tokens for testing
  3. Escrow Manager - Create and manage escrow transactions

1. Display Token Balances

Create a component to display all token balances including native SUI and mock tokens.
src/components/Balance.tsx
Key Features:
  • Queries balances for all coin types
  • Converts from smallest units (9 decimals) to human-readable format
  • Displays all balances in cards

2. Faucet

Create components to claim test tokens. All three mint components follow the same pattern.

Faucet Mock Coin

src/components/transaction/Faucet.tsx
Key Features:
  • Automatically fetches TreasuryCap objects from user’s wallet
  • Displays treasury caps in a dropdown
  • Accepts human-readable amounts (e.g., “1” = 1 token)
  • Converts to smallest units before sending transaction

3. Escrow Manager

Create a unified component to manage all escrow operations with tabs.
src/components/transaction/Escrow.tsx

Escrow Flow

1. Setup (Seller)

  1. Claim tokens using faucet components
  2. Check balance in Balance component

2. Create Escrow (Seller)

  1. Go to Create tab
  2. Select deposit coin type
  3. Choose specific coin from dropdown
  4. Select payment coin type to request
  5. Enter amount to request
  6. Click “Create Escrow”

3. Accept Escrow (Buyer)

  1. Get escrow object ID from seller
  2. Go to Accept tab
  3. Paste escrow object ID
  4. Coin types auto-detect
  5. Payment coin auto-selects
  6. Verify “You Will Receive” and “You Will Pay” amounts
  7. Click “Accept Escrow”

Alternative: Cancel Escrow (Seller)

  1. Go to Cancel tab (only before buyer accepts)
  2. Paste escrow object ID
  3. Coin types auto-detect
  4. Click “Cancel Escrow” to get deposit back

Best Practices

Amount Handling

Always convert amounts to smallest units:

Coin Queries

Use specific coin types for accurate queries:

Auto-Detection

Parse escrow type to extract coin types:

Error Handling

Always handle success and error callbacks:

Next Steps

  • Add loading states for better UX
  • Implement transaction history
  • Add escrow listing view
  • Create notification system for escrow events
  • Add escrow cancellation refund tracking

Congratulations! You’ve built a complete escrow dApp with minting, balance tracking, and full escrow management.