> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cdp.coinbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pay

> Send USDC payments on the Base network

Defined in the [Coinbase Wallet SDK](https://github.com/base/account-sdk)

> [!NOTE]
>
> 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.**
>
> **Try it out:** Test the `pay` function interactively in our [Base Pay SDK Playground](https://base.github.io/account-sdk/pay-playground).

## 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.

**PayerInfo Properties**

**requests** `array` *required*

Array of information requests from the payer.

**InfoRequest Properties**

**type** `string` *required*

The type of information being requested.

**Possible values:** `'email' | 'physicalAddress' | 'phoneNumber' | 'name' | 'onchainAddress'`

**optional** `boolean`

Whether this information is optional. Default: false

**callbackURL** `string`

Optional callback URL for server-side validation.

## Returns

**result** `PayResult`

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

**Payment Success Properties**

**id** `string`

Transaction hash - use this to check payment status.

**amount** `string`

Amount that was sent.

**to** `string`

Address that received the payment.

**payerInfoResponses** `object`

Optional responses from information requests.

## Errors

The `pay` function throws an error when the payment fails. The error object contains a message explaining what went wrong.

```typescript Basic Payment lines wrap expandable theme={null}
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}`);
}
```

```typescript Payment with Data Collection lines wrap expandable theme={null}
try {
  const payment = await pay({
    amount: "25.00",
    to: "0x1234567890123456789012345678901234567890",
    payerInfo: {
      requests: [
        { type: 'email', optional: false },
        { type: 'phoneNumber', optional: true },
        { type: 'physicalAddress', optional: true }
      ],
      callbackURL: "https://your-api.com/validate"
    }
  });
  
  console.log(`Payment sent! Transaction ID: ${payment.id}`);
  
  // Access collected user information
  if (payment.payerInfoResponses) {
    console.log('Email:', payment.payerInfoResponses.email);
    
    if (payment.payerInfoResponses.phoneNumber) {
      console.log('Phone:', payment.payerInfoResponses.phoneNumber.number);
      console.log('Country:', payment.payerInfoResponses.phoneNumber.country);
    }
    
    if (payment.payerInfoResponses.physicalAddress) {
      const address = payment.payerInfoResponses.physicalAddress;
      console.log('Address:', address.address1);
      console.log('City:', address.city);
      console.log('State:', address.state);
      console.log('Postal Code:', address.postalCode);
      console.log('Recipient Name:', `${address.name.firstName} ${address.name.familyName}`);
    }
  }
} catch (error) {
  console.error(`Payment failed: ${error.message}`);
}
```

```typescript Basic Success Response theme={null}
{
  id: "0xabcd1234...",
  amount: "10.50",
  to: "0x1234567890123456789012345678901234567890"
}
```

```typescript Success Response with Data Collection lines wrap expandable theme={null}
{
  id: "0xabcd1234...",
  amount: "25.00",
  to: "0x1234567890123456789012345678901234567890",
  payerInfoResponses: {
    email: "user@example.com",
    phoneNumber: {
      number: "+1234567890",
      country: "US"
    },
    physicalAddress: {
      address1: "123 Main St",
      city: "San Francisco",
      state: "CA",
      postalCode: "94105",
      country: "US",
      name: {
        firstName: "John",
        familyName: "Doe"
      }
    }
  }
}
```

```typescript Error (thrown) theme={null}
{
  "code": 4001,
  "message": "Request rejected",
  "stack": "Error: Request rejected\n    at getEthProviderError..."
}
```

## 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:

```typescript Error Handling lines wrap expandable theme={null}
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}`);
}
```
