Escrow is a financial arrangement where a neutral third party temporarily holds funds/assets while two parties complete a transaction. It ensures:
- Security: Funds are protected until conditions are met.
- Trust: Neither party can act unilaterally.
- Automation: Rules are enforced programmatically (via smart contracts).
| Feature | Description |
|---|---|
| Mutual Approval | Both buyer and seller must approve to release funds. |
| Automatic Execution | Transfers funds instantly when both parties approve. |
| Cancellation | Allows refunds (when funded) if the transaction fails. |
| Transparency | All actions logged as on-chain events |
| Security Checks | Prevents invalid states. |
| Component | Type | Description |
|---|---|---|
buyer |
AccountId | Initiator/asset depositor |
seller |
AccountId | Recipient of assets |
amount |
Balance | Agreed transaction value |
buyer_approved |
bool | Buyer's confirmation flag |
seller_approved |
bool | Seller's confirmation flag |
state |
EscrowState | Current lifecycle stage (see state diagram) |
Key Points:
- Buyer initiates by specifying seller/amount
- Prevents self-dealing with
buyer == sellercheck - Auto-increments escrow IDs
Key Points:
- Only buyer can deposit
- Exact amount required
- Must be in
Createdstate
Key Points:
- Buyer and seller must call separately
- Prevents duplicate approvals
- Funds transfer only after mutual consent
Key Points:
- Either party can cancel
- Refund only if funds were deposited
- Completed escrows cannot be canceled
stateDiagram-v2
[*] --> Created
Created --> Funded : deposit_assets()\n
Created --> Canceled : cancel_escrow()\n
Funded --> Completed : complete_escrow()\n
Funded --> Canceled : cancel_escrow()\n
Completed --> [*]
Canceled --> [*]
sequenceDiagram
participant B as Buyer
participant C as Contract
participant S as Seller
B->>C: initiate_escrow(seller, amount)
activate C
C-->>B: escrow_id
deactivate C
Note right of C: State: Created
B->>C: deposit_assets(escrow_id) + amount
activate C
C-->>B: Ok
deactivate C
Note right of C: State: Funded
B->>C: complete_escrow(escrow_id)
activate C
C->>C: Mark buyer_approved = true
C-->>B: Ok
deactivate C
S->>C: complete_escrow(escrow_id)
activate C
C->>C: Mark seller_approved = true
alt Both approved?
C->>S: Transfer funds
Note right of C: State: Completed
end
C-->>S: Ok
deactivate C
alt Cancellation
B->>C: cancel_escrow(escrow_id)
activate C
alt State == Funded
C->>B: Refund
end
Note right of C: State: Canceled
C-->>B: Ok
deactivate C
end