transferNativeToken
Transfer BNB tokens between addresses securely on Binance Smart Chain through the BSC MCP Server. Specify recipient and amount for direct native token transactions.
Instructions
Transfer native token (BNB)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | ||
| recipientAddress | Yes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"amount": {
"type": "string"
},
"recipientAddress": {
"type": "string"
}
},
"required": [
"recipientAddress",
"amount"
],
"type": "object"
}
Implementation Reference
- src/tools/transferNativeToken.ts:12-48 (handler)Handler function that sends native token (BNB) transaction using walletClient.sendTransaction to the recipient address with parsed amount, handles success and error responses with transaction URLs.async ({ recipientAddress, amount }) => { let txHash = undefined; try { const account = await getAccount(); txHash = await walletClient(account).sendTransaction({ to: recipientAddress as `0x${string}`, value: parseEther(amount), }); const txUrl = await checkTransactionHash(txHash) return { content: [ { type: "text", text: `Transaction sent successfully. ${txUrl}`, url: txUrl, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); const txUrl = buildTxUrl(txHash); return { content: [ { type: "text", text: `transaction failed: ${errorMessage}`, url: txUrl, }, ], isError: true, }; } }
- Input schema defining recipientAddress and amount as strings, validated with Zod.recipientAddress: z.string(), amount: z.string(), },
- src/tools/transferNativeToken.ts:7-50 (registration)Registration function that adds the 'Send_BNB' tool to the MCP server with description, input schema, and handler.export function registerTransferNativeToken(server: McpServer) { server.tool("Send_BNB", "💎Transfer native token (BNB), Before execution, check the wallet information first", { recipientAddress: z.string(), amount: z.string(), }, async ({ recipientAddress, amount }) => { let txHash = undefined; try { const account = await getAccount(); txHash = await walletClient(account).sendTransaction({ to: recipientAddress as `0x${string}`, value: parseEther(amount), }); const txUrl = await checkTransactionHash(txHash) return { content: [ { type: "text", text: `Transaction sent successfully. ${txUrl}`, url: txUrl, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); const txUrl = buildTxUrl(txHash); return { content: [ { type: "text", text: `transaction failed: ${errorMessage}`, url: txUrl, }, ], isError: true, }; } } ); }
- src/main.ts:27-27 (registration)Calls the registerTransferNativeToken function to register the tool on the main MCP server instance.registerTransferNativeToken(server);
- src/main.ts:7-7 (registration)Imports the registerTransferNativeToken function from the tool module.import { registerTransferNativeToken } from "./tools/transferNativeToken.js";