Swap tokens
Execute a token swap within a wallet.
Prerequisites
- Swaps must be enabled in the Privy Dashboard
- Gas sponsorship must be configured for your app
Authorizations
Basic Auth header with your app ID as the username and your app secret as the password.
Headers
ID of your Privy app.
Request authorization signature. If multiple signatures are required, they should be comma separated.
Idempotency keys ensure API requests are executed only once within a 24-hour window.
Path Parameters
ID of the wallet.
Body
Input for executing a token swap.
Amount in base units (e.g., wei for ETH). Must be a non-negative integer string.
1 - 78^\d+$The input side of a swap request, including token and chain.
The output side of a swap execution request.
Whether the amount refers to the input token (exact_input) or output token (exact_output).
exact_input, exact_output Maximum slippage tolerance in basis points (e.g., 50 for 0.5%).
0 <= x <= 10000Optional fee configuration for the swap. If omitted, cross-chain swaps only charge provider fees.
{ "type": "total_fee_bps", "value": 50 }Response
Swap initiated successfully.
Response for a swap action.
The ID of the wallet action.
The current status of the wallet action.
pending, succeeded, rejected, failed The ID of the wallet involved in the action.
ISO 8601 timestamp of when the wallet action was created.
swap CAIP-2 chain identifier for the swap.
Token address or "native" for the token being sold.
Token address or "native" for the token being bought.
Exact base-unit amount of input token. Populated after on-chain confirmation.
Exact base-unit amount of output token. Populated after on-chain confirmation.
Top-level failure context for the wallet action. Present on rejected or failed actions when available.
The steps of the wallet action. Only returned if ?include=steps is provided.
A wallet action step consisting of an EVM transaction.
- EVMTransactionWalletActionStep
- EVMUserOperationWalletActionStep
- SVMTransactionWalletActionStep
- ExternalTransactionWalletActionStep
Destination chain CAIP-2 identifier. Present for cross-chain swaps.
Estimated fee breakdown from the provider quote.
Estimated fee paid to the relayer.
- RelayerFee
- PrivyFee
- DeveloperFee
{
"type": "privy",
"recipient": "0x1234567890abcdef1234567890abcdef12345678",
"amount": "0.20"
}Estimated source-chain gas cost from the provider quote.
{
"base_amount": "100000000000000",
"amount": "0.0001",
"gas_asset": "ETH"
}Actual fees paid for the swap. Populated after on-chain confirmation.
Estimated fee paid to the relayer.
- RelayerFee
- PrivyFee
- DeveloperFee
{
"type": "privy",
"recipient": "0x1234567890abcdef1234567890abcdef12345678",
"amount": "0.20"
}Actual source-chain gas cost. Populated after on-chain confirmation.
{
"base_amount": "100000000000000",
"amount": "0.0001",
"gas_asset": "ETH"
}
