Documentation

P2P Escrow

Create secure peer-to-peer deals with automatic escrow. Funds are held by the contract until both parties confirm delivery, with built-in dispute and expiry mechanisms.

Use Cases

  • Peer-to-peer trading with trustless settlement
  • Freelance payments with delivery confirmation
  • OTC deals with automatic escrow custody

How It Works

  1. Buyer creates a deal specifying seller, token, amount, and deadline
  2. Buyer funds the deal (tokens held by the contract)
  3. Seller marks goods/services as delivered
  4. Buyer confirms receipt, releasing funds to the seller
  5. If anything goes wrong, the buyer can dispute or funds auto-return after deadline

Execute Methods

MethodParametersDescription
create_dealseller, token_id, amount, description, deadlineBuyer creates a new deal. Returns deal ID.
fund_dealdeal_id: u64Buyer deposits tokens into escrow.
mark_delivereddeal_id: u64Seller marks goods as delivered.
confirm_receiveddeal_id: u64Buyer confirms receipt. Releases funds to seller.
disputedeal_id: u64Buyer flags a dispute on a funded deal.
cancel_dealdeal_id: u64Buyer cancels a deal before funding.
refund_expireddeal_id: u64Return funds to buyer after deadline passes.

Query Methods

MethodParametersReturnsDescription
get_dealdeal_id: u64DealFull deal details
get_deal_count--u64Total number of deals created

Key Types

DealStatus

pub enum DealStatus {
    Created,    // Deal created, not yet funded
    Funded,     // Buyer deposited tokens
    Delivered,  // Seller marked as delivered
    Completed,  // Buyer confirmed, funds released
    Disputed,   // Buyer raised a dispute
    Cancelled,  // Deal cancelled before funding
    Refunded,   // Funds returned after expiry
}

Deal

pub struct Deal {
    pub id: u64,
    pub buyer: Address,
    pub seller: Address,
    pub token_id: TokenId,
    pub amount: u128,
    pub description: String,
    pub status: DealStatus,
    pub created_at: u64,
    pub funded_at: u64,
    pub deadline: u64,
}

CLI Usage

# Deploy
norn wallet deploy-loom --name my-escrow
 
# Upload bytecode
norn wallet upload-bytecode --loom-id <LOOM_ID> \
  --bytecode escrow.wasm
 
# Execute (borsh-encoded input)
norn wallet execute-loom --loom-id <LOOM_ID> --input <HEX>
 
# Query a deal
norn wallet query-loom --loom-id <LOOM_ID> --input <HEX>