create_tx
Generate cross-chain swap transaction data for the deBridge DLN protocol to transfer tokens between different blockchain networks.
Instructions
Create a cross-chain swap transaction via the deBridge DLN protocol. Returns transaction data that must be signed and submitted to the source chain. Use search_tokens first to resolve token names to addresses and get_supported_chains to find chain IDs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| srcChainId | Yes | Source chain ID. Examples: '1' (Ethereum), '56' (BNB Chain), '137' (Polygon), '7565164' (Solana) | |
| srcChainTokenIn | Yes | Token address on the source chain to swap from. Use 0x0000000000000000000000000000000000000000 for native tokens (ETH, BNB, etc.) | |
| srcChainTokenInAmount | Yes | Amount of source token in smallest units (wei, lamports). Example: '1000000000000000000' for 1 ETH (18 decimals), '1000000' for 1 USDC (6 decimals) | |
| dstChainId | Yes | Destination chain ID. Examples: '1' (Ethereum), '56' (BNB Chain), '42161' (Arbitrum) | |
| dstChainTokenOut | Yes | Token address on the destination chain to receive | |
| dstChainTokenOutAmount | No | Output amount in smallest units, or 'auto' for best available quote (default: 'auto') | auto |
| dstChainTokenOutRecipient | Yes | Wallet address on the destination chain that will receive the tokens | |
| srcChainOrderAuthorityAddress | Yes | Address on the source chain authorized to manage the order (cancel, etc). Typically the sender's wallet address | |
| dstChainOrderAuthorityAddress | Yes | Address on the destination chain authorized to manage the order. Typically the recipient's wallet address | |
| affiliateFeePercent | No | Affiliate fee percentage (e.g. 0.1 for 0.1%) | |
| affiliateFeeRecipient | No | Wallet address to receive affiliate fees | |
| prependOperatingExpenses | No | Whether to prepend estimated operating expenses to the input amount |
Implementation Reference
- src/tools/create-tx.ts:64-110 (handler)The main handler function that executes the create_tx tool logic. It constructs the DLN API URL, sets query parameters from the input, makes the fetch request, and returns either the transaction data or an error response.
async (params) => { const url = new URL(`${DLN_API_BASE}/dln/order/create-tx`); url.searchParams.set("srcChainId", params.srcChainId); url.searchParams.set("srcChainTokenIn", params.srcChainTokenIn); url.searchParams.set("srcChainTokenInAmount", params.srcChainTokenInAmount); url.searchParams.set("dstChainId", params.dstChainId); url.searchParams.set("dstChainTokenOut", params.dstChainTokenOut); url.searchParams.set("dstChainTokenOutAmount", params.dstChainTokenOutAmount); url.searchParams.set("dstChainTokenOutRecipient", params.dstChainTokenOutRecipient); url.searchParams.set("srcChainOrderAuthorityAddress", params.srcChainOrderAuthorityAddress); url.searchParams.set("dstChainOrderAuthorityAddress", params.dstChainOrderAuthorityAddress); if (params.affiliateFeePercent !== undefined) { url.searchParams.set("affiliateFeePercent", String(params.affiliateFeePercent)); } if (params.affiliateFeeRecipient) { url.searchParams.set("affiliateFeeRecipient", params.affiliateFeeRecipient); } if (params.prependOperatingExpenses !== undefined) { url.searchParams.set("prependOperatingExpenses", String(params.prependOperatingExpenses)); } const response = await fetch(url.toString()); const body = await response.json(); if (!response.ok) { return { isError: true, content: [ { type: "text" as const, text: JSON.stringify({ error: body.message ?? body.error ?? body, statusCode: response.status }), }, ], }; } return { content: [ { type: "text" as const, text: JSON.stringify(body), }, ], }; }, - src/tools/create-tx.ts:12-62 (schema)Input schema definition using Zod validation for the create_tx tool. Defines all required and optional parameters including source/destination chain IDs, token addresses, amounts, recipient addresses, and optional affiliate fee settings.
inputSchema: { srcChainId: z .string() .describe("Source chain ID. Examples: '1' (Ethereum), '56' (BNB Chain), '137' (Polygon), '7565164' (Solana)"), srcChainTokenIn: z .string() .describe( "Token address on the source chain to swap from. Use 0x0000000000000000000000000000000000000000 for native tokens (ETH, BNB, etc.)", ), srcChainTokenInAmount: z .string() .describe( "Amount of source token in smallest units (wei, lamports). Example: '1000000000000000000' for 1 ETH (18 decimals), '1000000' for 1 USDC (6 decimals)", ), dstChainId: z .string() .describe("Destination chain ID. Examples: '1' (Ethereum), '56' (BNB Chain), '42161' (Arbitrum)"), dstChainTokenOut: z .string() .describe("Token address on the destination chain to receive"), dstChainTokenOutAmount: z .string() .optional() .default("auto") .describe("Output amount in smallest units, or 'auto' for best available quote (default: 'auto')"), dstChainTokenOutRecipient: z .string() .describe("Wallet address on the destination chain that will receive the tokens"), srcChainOrderAuthorityAddress: z .string() .describe( "Address on the source chain authorized to manage the order (cancel, etc). Typically the sender's wallet address", ), dstChainOrderAuthorityAddress: z .string() .describe( "Address on the destination chain authorized to manage the order. Typically the recipient's wallet address", ), affiliateFeePercent: z .number() .optional() .describe("Affiliate fee percentage (e.g. 0.1 for 0.1%)"), affiliateFeeRecipient: z .string() .optional() .describe("Wallet address to receive affiliate fees"), prependOperatingExpenses: z .boolean() .optional() .describe("Whether to prepend estimated operating expenses to the input amount"), }, - src/tools/create-tx.ts:6-112 (registration)The registerCreateTx function that registers the 'create_tx' tool with the MCP server, including its description, input schema, and handler callback.
export function registerCreateTx(server: McpServer) { server.registerTool( "create_tx", { description: "Create a cross-chain swap transaction via the deBridge DLN protocol. Returns transaction data that must be signed and submitted to the source chain. Use search_tokens first to resolve token names to addresses and get_supported_chains to find chain IDs.", inputSchema: { srcChainId: z .string() .describe("Source chain ID. Examples: '1' (Ethereum), '56' (BNB Chain), '137' (Polygon), '7565164' (Solana)"), srcChainTokenIn: z .string() .describe( "Token address on the source chain to swap from. Use 0x0000000000000000000000000000000000000000 for native tokens (ETH, BNB, etc.)", ), srcChainTokenInAmount: z .string() .describe( "Amount of source token in smallest units (wei, lamports). Example: '1000000000000000000' for 1 ETH (18 decimals), '1000000' for 1 USDC (6 decimals)", ), dstChainId: z .string() .describe("Destination chain ID. Examples: '1' (Ethereum), '56' (BNB Chain), '42161' (Arbitrum)"), dstChainTokenOut: z .string() .describe("Token address on the destination chain to receive"), dstChainTokenOutAmount: z .string() .optional() .default("auto") .describe("Output amount in smallest units, or 'auto' for best available quote (default: 'auto')"), dstChainTokenOutRecipient: z .string() .describe("Wallet address on the destination chain that will receive the tokens"), srcChainOrderAuthorityAddress: z .string() .describe( "Address on the source chain authorized to manage the order (cancel, etc). Typically the sender's wallet address", ), dstChainOrderAuthorityAddress: z .string() .describe( "Address on the destination chain authorized to manage the order. Typically the recipient's wallet address", ), affiliateFeePercent: z .number() .optional() .describe("Affiliate fee percentage (e.g. 0.1 for 0.1%)"), affiliateFeeRecipient: z .string() .optional() .describe("Wallet address to receive affiliate fees"), prependOperatingExpenses: z .boolean() .optional() .describe("Whether to prepend estimated operating expenses to the input amount"), }, }, async (params) => { const url = new URL(`${DLN_API_BASE}/dln/order/create-tx`); url.searchParams.set("srcChainId", params.srcChainId); url.searchParams.set("srcChainTokenIn", params.srcChainTokenIn); url.searchParams.set("srcChainTokenInAmount", params.srcChainTokenInAmount); url.searchParams.set("dstChainId", params.dstChainId); url.searchParams.set("dstChainTokenOut", params.dstChainTokenOut); url.searchParams.set("dstChainTokenOutAmount", params.dstChainTokenOutAmount); url.searchParams.set("dstChainTokenOutRecipient", params.dstChainTokenOutRecipient); url.searchParams.set("srcChainOrderAuthorityAddress", params.srcChainOrderAuthorityAddress); url.searchParams.set("dstChainOrderAuthorityAddress", params.dstChainOrderAuthorityAddress); if (params.affiliateFeePercent !== undefined) { url.searchParams.set("affiliateFeePercent", String(params.affiliateFeePercent)); } if (params.affiliateFeeRecipient) { url.searchParams.set("affiliateFeeRecipient", params.affiliateFeeRecipient); } if (params.prependOperatingExpenses !== undefined) { url.searchParams.set("prependOperatingExpenses", String(params.prependOperatingExpenses)); } const response = await fetch(url.toString()); const body = await response.json(); if (!response.ok) { return { isError: true, content: [ { type: "text" as const, text: JSON.stringify({ error: body.message ?? body.error ?? body, statusCode: response.status }), }, ], }; } return { content: [ { type: "text" as const, text: JSON.stringify(body), }, ], }; }, ); } - src/server.ts:38-38 (registration)Registration call where registerCreateTx is invoked to add the create_tx tool to the server instance.
registerCreateTx(server); - src/server.ts:8-8 (registration)Import statement that imports the registerCreateTx function from the tools module.
import { registerCreateTx } from "./tools/create-tx.js";