generate_deploy_link
Generate a TON deployment deeplink for a compiled Tolk contract by providing the compiled code BoC and optional initial data. Computes the contract address and outputs ton:// deeplinks for wallet deployment.
Instructions
Generates a TON deployment deeplink for a compiled Tolk contract. Accepts the compiled code BoC (base64) and optionally initial data BoC. Computes the contract address and returns ton:// deeplinks for wallet deployment.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| codeBoc64 | Yes | Base64-encoded BoC of the compiled contract code (from compile_tolk output) | |
| initialDataBoc64 | No | Base64-encoded BoC for the contract initial data cell (default: empty cell) | |
| workchain | No | Target workchain ID (default: 0, the basechain) | |
| amount | No | Amount in nanoTON to send with deploy message (default: "50000000" = 0.05 TON) |
Implementation Reference
- src/tools.ts:228-230 (registration)Registration of the 'generate_deploy_link' tool via server.tool() with its description.
server.tool( "generate_deploy_link", "Generates a TON deployment deeplink for a compiled Tolk contract. " + - src/tools.ts:233-245 (schema)Input schema for generate_deploy_link: codeBoc64 (required), initialDataBoc64 (optional), workchain (optional), amount (optional regex-validated string).
{ codeBoc64: z.string().describe("Base64-encoded BoC of the compiled contract code (from compile_tolk output)"), initialDataBoc64: z .string() .optional() .describe("Base64-encoded BoC for the contract initial data cell (default: empty cell)"), workchain: z.number().optional().describe("Target workchain ID (default: 0, the basechain)"), amount: z .string() .regex(/^\d+$/, "amount must be a non-negative integer string (nanoTON)") .optional() .describe('Amount in nanoTON to send with deploy message (default: "50000000" = 0.05 TON)'), }, - src/tools.ts:246-319 (handler)Handler function that decodes BoC, computes contract address using @ton/core, generates ton:// and Tonkeeper deeplinks, and returns deployment info.
async (args) => { const { codeBoc64, initialDataBoc64, workchain, amount } = args; const wc = workchain ?? 0; const deployAmount = amount ?? "50000000"; let code: Cell; try { code = Cell.fromBase64(codeBoc64); } catch (err) { return { content: [{ type: "text", text: `Error: invalid codeBoc64 — ${getErrorMessage(err)}` }], isError: true, }; } let data: Cell; if (initialDataBoc64) { try { data = Cell.fromBase64(initialDataBoc64); } catch (err) { return { content: [{ type: "text", text: `Error: invalid initialDataBoc64 — ${getErrorMessage(err)}` }], isError: true, }; } } else { data = beginCell().endCell(); } const stateInit = { code, data }; const address = contractAddress(wc, stateInit); const stateInitCell = beginCell().store(storeStateInit(stateInit)).endCell(); const stateInitBoc64 = stateInitCell.toBoc().toString("base64"); const tonLink = `ton://transfer/${address.toString()}?amount=${deployAmount}&stateInit=${encodeURIComponent(stateInitBoc64)}`; const tonkeeperLink = `https://app.tonkeeper.com/transfer/${address.toString()}?amount=${deployAmount}&stateInit=${encodeURIComponent(stateInitBoc64)}`; const lines: string[] = [ `## Deployment Information`, "", `**Contract address:** \`${address.toString()}\``, `**Address (raw):** \`${address.toRawString()}\``, `**Target workchain:** ${wc}`, `**Deploy amount:** ${deployAmount} nanoTON (${Number(deployAmount) / 1e9} TON)`, "", "### Deployment Links", "", `**ton:// deeplink** (universal):`, "```", tonLink, "```", "", `**Tonkeeper link:**`, "```", tonkeeperLink, "```", "", "### How to deploy", "", "1. Open one of the links above in a TON wallet (Tonkeeper, Tonhub, etc.)", "2. Confirm the transaction — it will deploy the contract to the address shown above", "3. The contract address is deterministic — same code + data always produces the same address", "", `> **Note:** Different initial data produces a different contract address. ` + `If no initialDataBoc64 was provided, an empty cell was used.`, "", "### StateInit BoC (base64)", "```", stateInitBoc64, "```", ]; return { content: [{ type: "text", text: lines.join("\n") }] }; }, - src/tools.ts:6-8 (helper)Helper function getErrorMessage used by the handler for error formatting.
function getErrorMessage(err: unknown): string { return err instanceof Error ? err.message : String(err); } - src/tools.ts:1-4 (helper)Imports used by the tool: @ton/core (Cell, beginCell, contractAddress, storeStateInit), zod for schema validation.
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { beginCell, Cell, contractAddress, storeStateInit } from "@ton/core"; import { getTolkCompilerVersion, runTolkCompiler } from "@ton/tolk-js"; import { z } from "zod";