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. Try it out: Test the pay function interactively in our Base Pay SDK Playground .
Parameters
Amount of USDC to send (e.g., “10.50” or “0.01”).
Ethereum address to send USDC to (must start with 0x). Pattern: ^0x[0-9a-fA-F]{40}$
Set to true to use Base Sepolia testnet instead of mainnet. Default: false
Optional payer information configuration for data callbacks. Show PayerInfo properties
Array of information requests from the payer. Show InfoRequest properties
The type of information being requested. Possible values: 'email' | 'physicalAddress' | 'phoneNumber' | 'name' | 'onchainAddress'
Whether this information is optional. Default: false
Optional callback URL for server-side validation.
Returns
Payment result on success. The function throws an error on failure. Show Payment Success properties
Transaction hash - use this to check payment status.
Address that received the payment.
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.
Basic Payment
Payment with Data Collection
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 } ` );
}
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 } ` );
}
Basic Success Response
Success Response with Data Collection
Error (thrown)
{
id : "0xabcd1234..." ,
amount : "10.50" ,
to : "0x1234567890123456789012345678901234567890"
}
{
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"
}
}
}
}
{
"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:
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 } ` );
}