---
name: bankr-x402-sdk-token-swaps
description: This skill should be used when the user asks to "swap tokens", "exchange ETH for USDC", "buy DEGEN", "sell tokens", "swap on Base", "trade crypto", "convert ETH to WETH", "exchange tokens", "token swap code", "0x routing", or any token swap operation. Also use for questions about ERC20 approvals, allowanceTarget, swap transaction execution, or building swap transactions with the Bankr SDK.
version: 1.1.0
---

# SDK Token Swaps

Build and execute token swaps with AI-powered 0x routing.

## Prompt Patterns

| Pattern | Example |
|---------|---------|
| Amount-based | "Swap 0.1 ETH to USDC" |
| Value-based | "Buy $100 worth of DEGEN" |
| Percentage | "Swap 50% of my ETH to USDC" |
| Sell all | "Sell all my DEGEN" |
| Chain-specific | "Swap ETH to USDC on Polygon" |

```
# Amount Swaps
"Swap 0.1 ETH to USDC"
"Exchange 100 USDC for WETH"
"Swap 1000 DEGEN to ETH"

# Value Swaps
"Buy $100 worth of DEGEN"
"Purchase $50 of ETH"

# Percentage Swaps
"Swap 50% of my ETH to USDC"
"Sell 25% of my DEGEN"

# Chain-Specific
"Swap 0.1 ETH to USDC on Base"
"Exchange 100 USDC for WETH on Ethereum"
```

## ERC20 Approval Handling

For ERC20 swaps (selling tokens other than ETH), approval is required before the swap.

```typescript
const result = await client.promptAndWait({
  prompt: "Swap 100 USDC to WETH",
});

const swapTx = result.transactions?.find(tx => tx.type === "swap");

// Check if approval is needed
if (swapTx?.metadata.approvalRequired) {
  // Execute pre-built approval transaction first
  await wallet.sendTransaction(swapTx.metadata.approvalTx);
}

// Then execute the swap
await wallet.sendTransaction(swapTx.metadata.transaction);
```

## Approval Fields

| Field | Description |
|-------|-------------|
| `approvalRequired` | Whether approval needed before swap |
| `approvalTx` | Pre-built approval transaction (ready to send) |
| `allowanceTarget` | 0x AllowanceHolder address (for manual approval) |

## Usage

```typescript
import { BankrClient } from "@bankr/sdk";

const client = new BankrClient({
  privateKey: process.env.BANKR_PRIVATE_KEY as `0x${string}`,
});

const result = await client.promptAndWait({
  prompt: "Swap 0.1 ETH to USDC on Base",
});

if (result.status === "completed" && result.transactions?.length) {
  const tx = result.transactions[0].metadata.transaction;
  await wallet.sendTransaction(tx);
}
```

## Supported Chains

| Chain | Native Token | Default |
|-------|-------------|---------|
| Base | ETH | Yes |
| Ethereum | ETH | No |
| Polygon | MATIC | No |
| Solana | SOL | No |

## Related Skills

- **sdk-capabilities**: Full list of supported operations
- **sdk-transaction-builder**: Other transaction types (transfers, NFTs)
- **sdk-wallet-operations**: Client setup and configuration


---
Source attribution: BankrBot
Original project: https://github.com/BankrBot/claude-plugins/blob/67d33d4ee8e1680ce823eb9fe9ad371326c6b5ec/x402-sdk-dev/skills/sdk-token-swaps/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Dave AI.

## Upstream license notice

MIT License

Copyright (c) 2024 Bankr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Dave AI resource metadata

Creator / publisher: BankrBot
Original project: https://github.com/BankrBot/claude-plugins/blob/67d33d4ee8e1680ce823eb9fe9ad371326c6b5ec/x402-sdk-dev/skills/sdk-token-swaps/SKILL.md
Attribution basis: Recovered original package and original project license at a pinned revision

Fields of work: Marketing, Sales
Roles: Business Development, Growth Marketer, Marketing Analyst, Product Marketer, Sales Engineer
Specialties: API
Tools: Bankr Sdk
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 5deb4cb5d46ce2aa20711ff9f306a8905bd6beaaa42545aaf970584ca6491a7d
Metadata reviewed: 2026-10-27
This metadata supersedes earlier Dave AI catalog attribution. Original instruction and supporting files are preserved.
