import { pay } from '@base-org/account';

try {
  const payment = await pay({
    amount: "10.50",
    to: "0x1234567890123456789012345678901234567890",
    testnet: false
  });
  console.log(`Payment sent! Transaction ID: ${payment.id}`);
} catch (error) {
  console.error(`Payment failed: ${error.message}`);
}
{
  id: "0xabcd1234...",
  amount: "10.50",
  to: "0x1234567890123456789012345678901234567890"
}
Defined in the Base Account SDK
The pay function is the core method of Base Pay that lets your users send USDC (digital dollars) on the Base network. No crypto knowledge required - we handle all the complexity. No fees for merchants or users.

Parameters

amount
string
required
Amount of USDC to send (e.g., “10.50” or “0.01”).
to
string
required
Ethereum address to send USDC to (must start with 0x).Pattern: ^0x[0-9a-fA-F]{40}$
testnet
boolean
Set to true to use Base Sepolia testnet instead of mainnet. Default: false
payerInfo
object
Optional payer information configuration for data callbacks.

Returns

result
PayResult
Payment result on success. The function throws an error on failure.

Errors

The pay function throws an error when the payment fails. The error object contains a message explaining what went wrong.
import { pay } from '@base-org/account';

try {
  const payment = await pay({
    amount: "10.50",
    to: "0x1234567890123456789012345678901234567890",
    testnet: false
  });
  console.log(`Payment sent! Transaction ID: ${payment.id}`);
} catch (error) {
  console.error(`Payment failed: ${error.message}`);
}
{
  id: "0xabcd1234...",
  amount: "10.50",
  to: "0x1234567890123456789012345678901234567890"
}

Error Handling

The pay function throws errors instead of returning a result. Always wrap calls to pay in a try-catch block to handle errors gracefully:
try {
  const payment = await pay({
    amount: "10.00",
    to: "0xRecipient"
  });
  // Payment succeeded, use payment.id for tracking
  console.log(`Payment sent! Transaction ID: ${payment.id}`);
} catch (error) {
  // Payment failed
  console.error(`Payment failed: ${error.message}`);
}