Skip to main content
Glama

Build unsigned swap transaction

build_swap_tx
Read-only

Build the UNSIGNED transaction for the best (or chosen) route, plus any ERC-20 approval needed first and an eth_call simulation when an RPC is configured. Never signs, never holds keys or funds, never asks for keys: hand the result to the user's wallet (broadcast_tx can then relay the signed bytes unchanged). Swap-chan packs the bag; you carry it through the gate. Result includes display markdown with chan images and a swapchan.com link: show it to the user. How to combine this with the other tools: swapchan_playbook (workflows: find-money, best-swap, rebalance, revoke-approvals, bridge-stuck, token-safety, recover-old-wallet).

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "fromChainId": "<fromChainId>",
      "toChainId": "<toChainId>",
      "fromToken": "<fromToken>",
      "toToken": "<toToken>",
      "taker": "<taker>"
    },
    "name": "build_swap_tx"
  }
}

Input Schema

NameRequiredDescriptionDefault
refNoAlias of `partner`.
takerYesWallet address that will sign and send the transaction
amountNoHuman-readable amount of fromToken to sell, e.g. "1.5". Provide this OR amountBaseUnits.
partnerNoOptional SwapChan partner/affiliate id (from swapchan.com/partners). Quotes are attributed to it and the swapUrl carries ?ref= so the partner earns 5 bp (half of SwapChan's fee). Agent builders: register via POST https://api.swapchan.com/partners with the operator's payout address.
quoteIdNoReuse a quoteId from get_quote/compare_routes (still re-quotes if it expired)
toTokenYesToken address. Native gas token: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on EVM chains (ETH, POL...), 11111111111111111111111111111111 for SOL, bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8 for BTC, T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX, ltc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp9ysmq for LTC, D596YFweJQuHY1BbjazZYmAbt8jJPbKehC for DOGE, qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfnhks603 for BCH. SPL mints and TRC-20 addresses work as-is (e.g. Solana USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, Tron USDT TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t).
providerNoForce a specific provider from compare_routes instead of the best route
fromTokenYesToken address. Native gas token: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on EVM chains (ETH, POL...), 11111111111111111111111111111111 for SOL, bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8 for BTC, T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX, ltc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp9ysmq for LTC, D596YFweJQuHY1BbjazZYmAbt8jJPbKehC for DOGE, qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfnhks603 for BCH. SPL mints and TRC-20 addresses work as-is (e.g. Solana USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, Tron USDT TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t).
recipientNoAddress that receives the output on toChainId. Required for real execution when the destination is a different VM (e.g. EVM -> Solana/Bitcoin/Tron); omitted = indicative quote only.
toChainIdYesDestination chain id. Same as fromChainId for a same-chain swap; different for a cross-chain route.
fromChainIdYesChain id: 1 Ethereum, 8453 Base, 42161 Arbitrum, 10 Optimism, 137 Polygon, 56 BNB Chain, 43114 Avalanche, 59144 Linea, 534352 Scroll, 792703809 Solana, 8253038 Bitcoin, 728126428 Tron, plus THORChain-only 2000000002 Litecoin, 2000000003 Dogecoin, 2000000145 Bitcoin Cash (either side, THORChain only; sending them needs the native coin and returns an unsigned PSBT on /build or a deposit address from POST /utxo/deposit with the required memo). Non-EVM chains route via Relay, LI.FI and THORChain.
slippageBpsNoMax slippage in basis points (50 = 0.5%). Default 50, cap 300.
amountBaseUnitsNoExact amount in the token's smallest unit (wei). Provide this OR amount.
allowForeignRecipientNoSame-chain only: set true to pay out to `recipient` when it is not the taker. Off by default; the payout is pinned to the taker and a different recipient is refused.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedInput schema / properties / fromChainId / description
      Previous value: -"Chain id: 1 Ethereum, 8453 Base, 42161 Arbitrum, 10 Optimism, 137 Polygon, 56 BNB Chain, 43114 Avalanche, 59144 Linea, 534352 Scroll, 792703809 Solana, 8253038 Bitcoin, 728126428 Tron, plus receive-only 2000000002 Litecoin, 2000000003 Dogecoin, 2000000145 Bitcoin Cash (destination only, via THORChain; not accepted as the sending chain). Non-EVM chains route via Relay, LI.FI and THORChain."New value: +"Chain id: 1 Ethereum, 8453 Base, 42161 Arbitrum, 10 Optimism, 137 Polygon, 56 BNB Chain, 43114 Avalanche, 59144 Linea, 534352 Scroll, 792703809 Solana, 8253038 Bitcoin, 728126428 Tron, plus THORChain-only 2000000002 Litecoin, 2000000003 Dogecoin, 2000000145 Bitcoin Cash (either side, THORChain only; sending them needs the native coin and returns an unsigned PSBT on /build or a deposit address from POST /utxo/deposit with the required memo). Non-EVM chains route via Relay, LI.FI and THORChain."
  2. Changed3 schema fields changed
    • changedInput schema / properties / fromChainId / description
      Previous value: -"Chain id: 1 Ethereum, 8453 Base, 42161 Arbitrum, 10 Optimism, 137 Polygon, 56 BNB Chain, 43114 Avalanche, 59144 Linea, 534352 Scroll, 792703809 Solana, 8253038 Bitcoin, 728126428 Tron. Non-EVM chains route via Relay and LI.FI."New value: +"Chain id: 1 Ethereum, 8453 Base, 42161 Arbitrum, 10 Optimism, 137 Polygon, 56 BNB Chain, 43114 Avalanche, 59144 Linea, 534352 Scroll, 792703809 Solana, 8253038 Bitcoin, 728126428 Tron, plus receive-only 2000000002 Litecoin, 2000000003 Dogecoin, 2000000145 Bitcoin Cash (destination only, via THORChain; not accepted as the sending chain). Non-EVM chains route via Relay, LI.FI and THORChain."
    • changedInput schema / properties / fromToken / description
      Previous value: -"Token address. Native gas token: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on EVM chains (ETH, POL...), 11111111111111111111111111111111 for SOL, bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8 for BTC, T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX. SPL mints and TRC-20 addresses work as-is (e.g. Solana USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, Tron USDT TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)."New value: +"Token address. Native gas token: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on EVM chains (ETH, POL...), 11111111111111111111111111111111 for SOL, bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8 for BTC, T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX, ltc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp9ysmq for LTC, D596YFweJQuHY1BbjazZYmAbt8jJPbKehC for DOGE, qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfnhks603 for BCH. SPL mints and TRC-20 addresses work as-is (e.g. Solana USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, Tron USDT TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)."
    • changedInput schema / properties / toToken / description
      Previous value: -"Token address. Native gas token: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on EVM chains (ETH, POL...), 11111111111111111111111111111111 for SOL, bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8 for BTC, T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX. SPL mints and TRC-20 addresses work as-is (e.g. Solana USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, Tron USDT TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)."New value: +"Token address. Native gas token: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on EVM chains (ETH, POL...), 11111111111111111111111111111111 for SOL, bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8 for BTC, T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX, ltc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp9ysmq for LTC, D596YFweJQuHY1BbjazZYmAbt8jJPbKehC for DOGE, qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfnhks603 for BCH. SPL mints and TRC-20 addresses work as-is (e.g. Solana USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, Tron USDT TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)."
  3. Changed1 schema field changed
    • addedInput schema / properties / allowForeignRecipient
      Added value: +{
      +  "description": "Same-chain only: set true to pay out to `recipient` when it is not the taker. Off by default; the payout is pinned to the taker and a different recipient is refused.",
      +  "type": "boolean"
      +}
  4. Changed2 schema fields changed
    • addedInput schema / properties / partner
      Added value: +{
      +  "description": "Optional SwapChan partner/affiliate id (from swapchan.com/partners). Quotes are attributed to it and the swapUrl carries ?ref= so the partner earns 5 bp (half of SwapChan's fee). Agent builders: register via POST https://api.swapchan.com/partners with the operator's payout address.",
      +  "pattern": "^[a-z0-9-]{3,40}$",
      +  "type": "string"
      +}
    • addedInput schema / properties / ref
      Added value: +{
      +  "description": "Alias of `partner`.",
      +  "pattern": "^[a-z0-9-]{3,40}$",
      +  "type": "string"
      +}
  5. Changed4 schema fields changed
    • changedInput schema / properties / fromChainId / description
      Previous value: -"EVM chain id, e.g. 1 Ethereum, 8453 Base, 42161 Arbitrum, 10 Optimism, 137 Polygon, 56 BNB Chain, 43114 Avalanche, 59144 Linea, 534352 Scroll"New value: +"Chain id: 1 Ethereum, 8453 Base, 42161 Arbitrum, 10 Optimism, 137 Polygon, 56 BNB Chain, 43114 Avalanche, 59144 Linea, 534352 Scroll, 792703809 Solana, 8253038 Bitcoin, 728126428 Tron. Non-EVM chains route via Relay and LI.FI."
    • changedInput schema / properties / fromToken / description
      Previous value: -"Token contract address. Use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for the native gas token (ETH, POL...)."New value: +"Token address. Native gas token: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on EVM chains (ETH, POL...), 11111111111111111111111111111111 for SOL, bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8 for BTC, T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX. SPL mints and TRC-20 addresses work as-is (e.g. Solana USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, Tron USDT TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)."
    • addedInput schema / properties / recipient
      Added value: +{
      +  "description": "Address that receives the output on toChainId. Required for real execution when the destination is a different VM (e.g. EVM -> Solana/Bitcoin/Tron); omitted = indicative quote only.",
      +  "type": "string"
      +}
    • changedInput schema / properties / toToken / description
      Previous value: -"Token contract address. Use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for the native gas token (ETH, POL...)."New value: +"Token address. Native gas token: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE on EVM chains (ETH, POL...), 11111111111111111111111111111111 for SOL, bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8 for BTC, T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb for TRX. SPL mints and TRC-20 addresses work as-is (e.g. Solana USDC EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, Tron USDT TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)."
  6. First observed

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and destructiveHint=false (consistent with a non-mutating builder), and the description layers on non-obvious behavior: an approval call is bundled when needed, simulation only runs when an RPC is configured, and the response includes a `display` markdown block that must be shown to the user. That is context an agent cannot get from annotations or schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The core action and safety boundary are front-loaded in the first sentence. The whimsical aside ('Swap-chan packs the bag; you carry it through the gate') and the trailing playbook pointer are useful but slightly padded relative to the dense information around them.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 14-parameter, multi-VM, no-output-schema tool, the description covers the essential output shape (unsigned tx, approval, simulation, display markdown) and the signing boundary. It stops short of naming the concrete return fields an agent would need to extract the tx bytes, which matters more here because there is no output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all 14 parameters (including the amount/amountBaseUnits duality, quoteId reuse, and recipient requirements) are already documented in structured fields. The prose adds no parameter-level meaning beyond what the schema provides, so the baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('build the UNSIGNED transaction') and enumerates what the output bundle contains: the route tx, any ERC-20 approval, and an eth_call simulation. It is clearly separable from get_quote/compare_routes (quotes only), simulate_swap (read-only simulation), and broadcast_tx (relays signed bytes).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly routes the agent: hand the unsigned result to the user's wallet, or use broadcast_tx to relay signed bytes, and points to swapchan_playbook for named workflows. The 'never signs, never asks for keys' clause also implicitly draws the boundary against any signing tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.