Skip to main content

EscrowManager

The EscrowManager class handles the full escrow lifecycle — creation, funding, delivery, dispute, and resolution.

PDA Derivation

deriveEscrowAddress(buyer, seller, serviceMemo)

Seeds: ["escrow", buyer.toBytes(), seller.toBytes(), sha256(memo)]

Full Lifecycle Example

Building Instructions

buildCreateEscrowInstruction(params)

buildFundEscrowInstruction(buyer, escrowAddress, mint, amount)

Transfer tokens into the escrow account. Only the buyer can call this.

buildMarkDeliveredInstruction(seller, escrowAddress)

Seller signals that the service has been delivered.

buildReleaseFundsInstruction(buyer, seller, escrowAddress, mint, reputationAccounts?)

Buyer confirms delivery and releases funds to seller. Optionally updates seller’s reputation via CPI.

buildInitiateDisputeInstruction(disputeInitiator, escrowAddress, reason, reputationAccounts?)

Open a dispute with evidence.

buildResolveDisputeInstruction(arbiter, escrowAddress, buyer, seller, mint, favorSeller)

Arbiter resolves a dispute. Subject to 24-hour delay after dispute initiation.

buildClaimAutoReleaseInstruction(seller, escrowAddress, mint, reputationAccounts?)

Seller claims funds after timeout with no buyer action.

buildClaimTimeoutRefundInstruction(buyer, escrowAddress, mint)

Buyer claims refund after escrow timeout.

buildCancelEscrowInstruction(buyer, escrowAddress)

Cancel an unfunded escrow.

Querying Escrows

fetchEscrow(escrowAddress)

Returns: EscrowAccount | null

getEscrowsForBuyer(buyer)

getEscrowsForSeller(seller)

State Helpers

getStateLabel(state)

canAutoRelease(escrow)

Check if the escrow is eligible for auto-release (delivered + timeout passed).

canTimeoutRefund(escrow)

Check if the escrow is eligible for timeout refund.

getTimeUntilTimeout(escrow)

EscrowAccount

EscrowState Enum

Last modified on February 8, 2026