distributeNative
Send BNB to multiple addresses on Binance Smart Chain in a single transaction using the C98MultiSend contract for efficient bulk transfers.
Instructions
Send BNB to multiple addresses on BSC using the C98MultiSend contract.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"type": "object"
}
Implementation Reference
- index.js:103-149 (registration)Registration of the 'distributeNative' tool using McpServer.tool method, including schema and handler.server.tool( 'distributeNative', 'Send BNB to multiple addresses on BSC using the C98MultiSend contract.', z.object({ receivers: z.array(z.string().refine((val) => ethers.isAddress(val), { message: 'Invalid BSC address' })).describe('Array of BSC addresses to receive BNB.'), amounts: z.array(z.number().positive('Amount must be positive')).describe('Array of BNB amounts (in BNB, e.g., 0.1) to send to each receiver.') }), async ({ receivers, amounts }) => { try { // Validate inputs if (receivers.length !== amounts.length) { return { content: [{ type: 'text', text: 'Receivers and amounts arrays must have the same length' }], isError: true }; } // Convert amounts to wei and calculate total const amountsWei = amounts.map(amount => ethers.parseEther(amount.toString())); const totalAmountWei = amountsWei.reduce((sum, amount) => sum + BigInt(amount), BigInt(0)); // Prepare and send transaction const tx = await contract.transferMulti(receivers, amountsWei, { value: totalAmountWei, gasLimit: await contract.transferMulti.estimateGas(receivers, amountsWei, { value: totalAmountWei }) }); // Wait for transaction confirmation const receipt = await tx.wait(); return { content: [{ type: 'text', text: `BNB distribution successful. Tx Hash: ${receipt.hash}` }], isError: false }; } catch (error) { return { content: [{ type: 'text', text: `Error executing BNB distribution: ${error.message}` }], isError: true }; } } );
- index.js:112-148 (handler)The handler function for distributeNative: validates input lengths, converts BNB amounts to wei, calls contract.transferMulti with total value, waits for confirmation, returns tx hash or error.async ({ receivers, amounts }) => { try { // Validate inputs if (receivers.length !== amounts.length) { return { content: [{ type: 'text', text: 'Receivers and amounts arrays must have the same length' }], isError: true }; } // Convert amounts to wei and calculate total const amountsWei = amounts.map(amount => ethers.parseEther(amount.toString())); const totalAmountWei = amountsWei.reduce((sum, amount) => sum + BigInt(amount), BigInt(0)); // Prepare and send transaction const tx = await contract.transferMulti(receivers, amountsWei, { value: totalAmountWei, gasLimit: await contract.transferMulti.estimateGas(receivers, amountsWei, { value: totalAmountWei }) }); // Wait for transaction confirmation const receipt = await tx.wait(); return { content: [{ type: 'text', text: `BNB distribution successful. Tx Hash: ${receipt.hash}` }], isError: false }; } catch (error) { return { content: [{ type: 'text', text: `Error executing BNB distribution: ${error.message}` }], isError: true }; } }
- index.js:106-111 (schema)Zod schema for input validation: arrays of receiver addresses (validated as ethers addresses) and positive BNB amounts.z.object({ receivers: z.array(z.string().refine((val) => ethers.isAddress(val), { message: 'Invalid BSC address' })).describe('Array of BSC addresses to receive BNB.'), amounts: z.array(z.number().positive('Amount must be positive')).describe('Array of BNB amounts (in BNB, e.g., 0.1) to send to each receiver.') }),