You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: fern/docs/pages/0x-swap-api/additional-topics/swap-and-send.mdx
+87-1Lines changed: 87 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: "Swap and Send"
3
3
description: "Send swapped tokens directly to any address using the recipient parameter."
4
4
---
5
5
6
-
By default, swapped tokens are returned to the address that initiates the trade (the taker). With the `recipient` parameter, you can send the output tokens directly to any wallet address — in a single transaction.
6
+
By default, swapped tokens are returned to the address that initiates the trade (the `taker`). With the `recipient` parameter, you can send the output tokens directly to any wallet address — in a single transaction.
The API validates recipient at the price and quote stage — before any transaction is submitted — so no gas is wasted. There are two common error cases: an [invalid recipient address](/docs/0x-swap-api/additional-topics/swap-and-send#invalid-recipient-address) and passing recipient on a [wrap/unwrap operation](/docs/0x-swap-api/additional-topics/swap-and-send#wrapunwrap-operations).
201
+
202
+
### Invalid recipient address
203
+
204
+
The `recipient` value must be a valid Ethereum address — a 42-character hex string starting with `0x`. This error is triggered by things like a truncated address, a non-hex character, or passing a raw ENS name instead of a resolved address.
205
+
206
+
<Callouttype="info">
207
+
Always resolve ENS names to addresses client-side before passing them to the API. The `recipient` field does not support ENS.
208
+
</Callout>
209
+
210
+
```json
211
+
{
212
+
"name": "INPUT_INVALID",
213
+
"message": "The input is invalid",
214
+
"data": {
215
+
"zid": "0x8843f11733fbf965f90ef10a",
216
+
"details": [
217
+
{
218
+
"field": "recipient",
219
+
"reason": "Invalid ethereum address"
220
+
}
221
+
]
222
+
}
223
+
}
224
+
```
225
+
226
+
To catch this before hitting the API, validate the address client-side:
227
+
228
+
```typescript
229
+
import { isAddress, getAddress } from"viem";
230
+
231
+
const raw =userInputAddress;
232
+
233
+
if (!isAddress(raw)) {
234
+
thrownewError("Invalid recipient address");
235
+
}
236
+
237
+
const recipient =getAddress(raw); // normalizes to EIP-55 checksum
238
+
```
239
+
240
+
### Wrap/unwrap operations
241
+
242
+
`recipient` is not supported when `sellToken` and `buyToken` are a native/wrapped pair (e.g. ETH ↔ WETH, MATIC ↔ WMATIC). These operations don't route through the swap protocol, so the `recipient` field has no effect and is rejected.
243
+
244
+
```json
245
+
{
246
+
"name": "RECIPIENT_NOT_SUPPORTED",
247
+
"message": "The recipient parameter is not supported for wrap/unwrap operations",
248
+
"data": {
249
+
"zid": "0x05e4e8147d97597183b471ca"
250
+
}
251
+
}
252
+
```
253
+
254
+
Guard against this by detecting wrap/unwrap pairs before building your request and omitting `recipient` in those cases:
255
+
256
+
```typescript
257
+
const WRAP_UNWRAP_PAIRS: [string, string][] = [
258
+
["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"], // ETH ↔ WETH
0 commit comments