UNPKG

bnbchain-mcp

Version:

---

38 lines (37 loc) 1.24 kB
import { z } from "zod"; import { parseEther } from "viem"; import { client } from "../config.js"; export function registerTransferNativeToken(server) { server.tool("transferNativeToken", "Transfer native token (BNB)", { recipientAddress: z.string(), amount: z.string(), }, async ({ recipientAddress, amount }) => { try { const hash = await client.sendTransaction({ to: recipientAddress, value: parseEther(amount), }); return { content: [ { type: "text", text: `Transaction sent successfully. https://bscscan.com/tx/${hash}`, url: `https://bscscan.com/tx/${hash}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Transaction failed: ${errorMessage}`, }, ], isError: true, }; } }); }