Skip to main content

Documentation Index

Fetch the complete documentation index at: https://anypay-docs-sdk-0-15-0-updates.mintlify.app/llms.txt

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

Overview

Pay mode implements exact-output payment flows where you specify the precise amount the recipient receives. The user pays whatever is required from their available tokens across all chains. Trade type: EXACT_OUTPUT — fixed destination amount, variable input amount.

Quick start

import { Pay } from '0xtrails/widget'

<Pay
  apiKey="YOUR_API_KEY"
  to={{
    recipient: "0xYourAddress",
    currency: "USDC",
    chain: "base",
    amount: "50",
  }}
  onPaymentSuccess={({ sessionId }) => markOrderPaid(sessionId)}
/>
That is the minimum. Every other prop is optional.

Props

Required

PropTypeDescription
apiKeystringTrails API key
to.recipientstringWallet or contract address that receives the payment
to.currencystringToken symbol or address (e.g. "USDC", "ETH")
to.chainChainIdentifierDestination chain — name ("base"), chain ID, or viem Chain
to.amountstring | numberExact amount recipient receives in human-readable units

Source selection (optional)

Pre-select where the user pays from by adding a from object. Omit to let the user choose.
<Pay
  apiKey="YOUR_API_KEY"
  to={{ recipient: "0x...", currency: "USDC", chain: "base", amount: "50" }}
  from={{ currency: "ETH", chain: "ethereum" }}
/>
To control the payment method, set paymentMethod:
ValueMethod
"CONNECTED_WALLET"Connected wallet (default)
"CRYPTO_TRANSFER"QR code / address deposit
"CREDIT_DEBIT_CARD"Fiat on-ramp
"EXCHANGE"CEX transfer (Coinbase, Binance, etc.)

Destination options

PropTypeDescription
to.calldatastringABI-encoded calldata to execute on the destination chain after payment
to.defaultChainChainIdentifierDefault chain — user can change
to.defaultCurrencystringDefault token — user can change

Shared options

All focused components share these optional props:
PropTypeDescription
payMessagestringCustom message shown during the payment flow
appMetadataAppMetadataApp name, URL, and logo for wallet connection dialogs
devDevConfigDebug flags and internal URL overrides
theme"light" | "dark" | "auto"Widget color theme
renderInlinebooleanRender inline instead of as a modal
buttonTextstringCustom CTA text
slippageTolerancenumber | stringSlippage tolerance (e.g. 0.005 for 0.5%)
swapProviderRouteProviderPreferred same-chain swap provider
bridgeProviderRouteProviderPreferred bridge provider

Lifecycle callbacks

CallbackSignatureWhen it fires
onPaymentStart({ sessionId }) => voidUser initiates the payment flow
onPaymentSuccess({ sessionId }) => voidPayment completes successfully
onPaymentError({ sessionId, error }) => voidPayment encounters an error

Examples

Stablecoin payment

Accept 25 USDC on Polygon from any token on any chain:
import { Pay } from '0xtrails/widget'

<Pay
  apiKey="YOUR_API_KEY"
  to={{
    recipient: "0xYourMerchantAddress",
    currency: "USDC",
    chain: "polygon",
    amount: "25",
  }}
  onPaymentSuccess={({ sessionId }) => {
    updateOrderStatus(orderId, "paid", sessionId)
  }}
>
  <button>Pay $25</button>
</Pay>

Pre-select payment source

Lock the user to pay from ETH on Ethereum:
<Pay
  apiKey="YOUR_API_KEY"
  to={{
    recipient: "0x...",
    currency: "USDC",
    chain: "base",
    amount: "50",
  }}
  from={{
    currency: "ETH",
    chain: "ethereum",
  }}
  onPaymentSuccess={({ sessionId }) => console.log("paid", sessionId)}
/>

QR code / crypto transfer

Let the user pay by sending to an address directly:
<Pay
  apiKey="YOUR_API_KEY"
  paymentMethod="CRYPTO_TRANSFER"
  to={{
    recipient: "0x...",
    currency: "USDC",
    chain: "base",
    amount: "50",
  }}
/>

Fiat on-ramp

Let the user pay with a credit card:
<Pay
  apiKey="YOUR_API_KEY"
  paymentMethod="CREDIT_DEBIT_CARD"
  to={{
    recipient: "0x...",
    currency: "USDC",
    chain: "base",
    amount: "50",
  }}
/>

Payment with contract execution

Execute a function on the destination chain with the payment:
import { Pay } from '0xtrails/widget'
import { encodeFunctionData } from 'viem'

const mintCalldata = encodeFunctionData({
  abi: [{
    name: 'mint',
    type: 'function',
    stateMutability: 'payable',
    inputs: [{ name: 'to', type: 'address' }],
    outputs: [],
  }],
  functionName: 'mint',
  args: ['0xRecipientAddress'],
})

<Pay
  apiKey="YOUR_API_KEY"
  to={{
    recipient: "0xNFT_CONTRACT",
    currency: "ETH",
    chain: "arbitrum",
    amount: "0.00002",
    calldata: mintCalldata,
  }}
  onPaymentSuccess={({ sessionId }) => console.log("minted", sessionId)}
>
  <button>Mint NFT</button>
</Pay>

App branding and event handling

<Pay
  apiKey="YOUR_API_KEY"
  to={{
    recipient: "0x...",
    currency: "USDC",
    chain: "base",
    amount: "50",
  }}
  payMessage="Payment for Order #4821"
  appMetadata={{
    name: "My Store",
    url: "https://mystore.com",
    imageUrl: "https://mystore.com/logo.png",
  }}
  onPaymentStart={({ sessionId }) => console.log("started", sessionId)}
  onPaymentSuccess={({ sessionId }) => markOrderPaid(sessionId)}
  onPaymentError={({ error }) => console.error("failed", error)}
/>

See also