Skip to main content

OpenPayEscrow

The OpenPayEscrow contract holds payment funds in escrow until confirmed by the platform. It handles ERC-20 token payments and native BNB payments, applies platform fees, and enforces slippage protection via the price feed. Address (BSC Testnet): 0xe50464081b781AFE101EB40bC7e68Fd017c5e8f2 Explorer: View on BscScan

Constructor

Payment Struct

Each payment is stored on-chain with the following fields:

Payment Status Enum

Write Functions

createPayment

Create an ERC-20 token payment. The payer must have approved the escrow contract to spend the token amount beforehand.
The payer must call token.approve(escrowAddress, amount) before calling createPayment. Otherwise the transaction will revert.

createNativePayment

Create a payment using native BNB. The BNB amount is sent as msg.value.

confirmPayment

Confirm a pending payment. Splits funds between the merchant (minus fee) and the fee recipient. Owner only.
On confirmation:
  • Platform fee (default 2%) is sent to feeRecipient
  • Remaining amount is sent to the merchant
  • Payment status changes to Confirmed

refundPayment

Refund a pending payment back to the payer. Owner only.

expirePayment

Expire a payment that has passed its expiresAt timestamp. Funds are returned to the payer. Owner only.

Read Functions

getPayment

Retrieve full payment details by ID.

getQuote

Get a price quote for converting a USD amount to a specific token. Returns the token amount needed plus slippage bounds.

State Variables

Admin Functions (Owner Only)

Events

Security

Example: Reading a Payment with ethers.js