mcpField
B
Bankr x402 SDK - Token Swaps

Bankr x402 SDK - Token Swaps

github.com/bankrbotOther88365 installsUpdated 31w ago
Repository

About Bankr x402 SDK - Token Swaps

A Bankr SDK skill for building and executing token swaps through natural-language prompts. It supports amount-, value-, and percentage-based requests across several chains and exposes ERC20 approval details.

Key features

  1. 01Build swaps from natural-language prompts
  2. 02Swap by amount, value, or percentage
  3. 03Support Base, Ethereum, Polygon, and Solana
  4. 04Check ERC20 approval requirements
  5. 05Provide prebuilt approval transaction details

Use cases

  1. 01Swap a specified amount of one token for another
  2. 02Buy tokens for a target value
  3. 03Prepare a swap that needs ERC20 approval

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/bankrbot/claude-plugins --skill bankr-x402-sdk---token-swaps

After installing, type/bankr-x402-sdk---token-swapsin Claude Code to confirm it loaded.

Details

From the project README

SDK Token Swaps

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

Prompt Patterns

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

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

FieldDescription
approvalRequiredWhether approval needed before swap
approvalTxPre-built approval transaction (ready to send)
allowanceTarget0x AllowanceHolder address (for manual approval)

Usage

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

ChainNative TokenDefault
BaseETHYes
EthereumETHNo
PolygonMATICNo
SolanaSOLNo

Related Skills

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

Comments

Markdown supported