Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.x402r.org/llms.txt

Use this file to discover all available pages before exploring further.

Marketplace Operator

A marketplace operator deployment includes: EscrowPeriod, Freeze, StaticAddressCondition (arbiter), OrCondition (receiver OR arbiter for refunds), optional StaticFeeCalculator, and the PaymentOperator itself. All deployed via CREATE3 factories.
import { createPublicClient, createWalletClient, http } from 'viem';
import { baseSepolia } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
import { deployMarketplaceOperator } from '@x402r/core'

const publicClient = createPublicClient({
  chain: baseSepolia,
  transport: http(),
})

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const walletClient = createWalletClient({
  account,
  chain: baseSepolia,
  transport: http(),
})

const result = await deployMarketplaceOperator(walletClient, publicClient, {
  chainId: 84532,                         // Base Sepolia
  feeRecipient: account.address,          // receives operator fees
  arbiter: '0xArbiterAddress...',         // dispute resolver
  escrowPeriodSeconds: 604_800n,          // 7 days
  freezeDurationSeconds: 259_200n,        // 3 days max freeze
  operatorFeeBps: 100n,                   // 1% fee (optional)
})

console.log('Operator:', result.operatorAddress)
console.log('EscrowPeriod:', result.escrowPeriodAddress)
console.log('RefundRequest:', result.refundRequestAddress)
console.log('Freeze:', result.freezeAddress)
console.log('New deployments:', result.summary.newCount)
console.log('Existing (reused):', result.summary.existingCount)

Configuration Options

OptionTypeDescription
feeRecipientAddressAddress that receives operator fees
arbiterAddressArbiter address for dispute resolution
escrowPeriodSecondsbigintEscrow waiting period (e.g., 604800n for 7 days)
freezeDurationSecondsbigintHow long freezes last. Default: 0n (permanent until unfrozen)
operatorFeeBpsbigintFee in basis points. Default: 0n (no fee). 100n = 1%
interface MarketplaceOperatorDeployment {
  operatorAddress: Address
  escrowPeriodAddress: Address
  freezeAddress: Address | null
  refundRequestAddress: Address
  refundRequestEvidenceAddress: Address
  refundInEscrowConditionAddress: Address   // OR(Receiver, Arbiter)
  feeCalculatorAddress: Address | null      // null if no fee
  operatorConfig: OperatorConfig
  deployments: DeployResult[]
  summary: {
    newCount: number
    existingCount: number
    txHashes: `0x${string}`[]
  }
}
Redeploying with the same parameters is idempotent (CREATE3). It detects existing contracts and skips them. Check summary for what was new vs reused.
Compute addresses without deploying:
import { previewMarketplaceOperator } from '@x402r/core'

const preview = await previewMarketplaceOperator(publicClient, {
  chainId: 84532,
  feeRecipient: '0xYourAddress...',
  arbiter: '0xArbiterAddress...',
  escrowPeriodSeconds: 604_800n,
})

console.log('Operator will be at:', preview.operatorAddress)
console.log('EscrowPeriod will be at:', preview.escrowPeriodAddress)
SlotContractPurpose
AUTHORIZE_CONDITIONUsdcTvlLimitSafety limit on authorization
AUTHORIZE_RECORDEREscrowPeriodRecords authorization timestamp
CHARGE_CONDITION(none)No restrictions on charge
RELEASE_CONDITIONEscrowPeriodBlocks release during escrow period
REFUND_IN_ESCROW_CONDITIONOR(Receiver, Arbiter)Receiver or arbiter can approve
REFUND_POST_ESCROW_CONDITIONReceiverOnly receiver after escrow
FEE_CALCULATORStaticFeeCalculatorFixed percentage fee
FEE_RECIPIENTYour addressReceives fees
Deployment is supported on all supported chains. Pass the numeric chainId in the options.
Deployment requires gas fees. Ensure your wallet has ETH on the target network. On Base Sepolia, you can get testnet ETH from Base network faucets.

Delivery Protection Operator

For automated quality verification (AI garbage detection, schema validation), use the simpler delivery protection preset. No RefundRequest, Evidence, or Freeze contracts. The arbiter is the only address that can release funds.
import { deployDeliveryProtectionOperator } from '@x402r/core'

const deployment = await deployDeliveryProtectionOperator(
  walletClient,
  publicClient,
  {
    chainId: 84532,
    arbiter: '0xArbiterServiceAddress',
    feeRecipient: account.address,
    escrowPeriodSeconds: 300n,           // 5 minutes
  },
)

console.log('Operator:', deployment.operatorAddress)
console.log('EscrowPeriod:', deployment.escrowPeriodAddress)
console.log('ArbiterCondition:', deployment.arbiterConditionAddress)
OptionTypeDescription
chainIdnumberTarget chain
arbiterAddressOnly address that can call release()
feeRecipientAddressReceives protocol fees
escrowPeriodSecondsbigintVerification window before auto-refund
SlotContractPurpose
RELEASE_CONDITIONStaticAddressCondition(arbiter)Only arbiter can release
AUTHORIZE_RECORDEREscrowPeriodRecords authorization time
REFUND_IN_ESCROW_CONDITIONEscrowPeriodAnyone can refund after escrow expires
REFUND_POST_ESCROW_CONDITIONReceiverReceiver can refund post-escrow

Next Steps

Merchant Guide

Accept payments, release funds from escrow.

Payer Guide

Request refunds, freeze payments, submit evidence.

Examples

Runnable examples for every SDK operation.

Smart Contracts

On-chain architecture, conditions, and recorders.