Skip to main content
Glama
sendEgld.ts1.98 kB
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; import { Account, Address } from "@multiversx/sdk-core"; import { z } from "zod"; import { denominateEgldValue, getEntrypoint, getExplorerUrl, loadNetworkFromEnv, loadPemWalletFromEnv, } from "./utils.js"; export async function sendEgld( amount: string, receiver: string ): Promise<CallToolResult> { const denominated = denominateEgldValue(amount); const pem = loadPemWalletFromEnv(); const receiverAddress = Address.newFromBech32(receiver); const account = new Account(pem.secretKey); const network = loadNetworkFromEnv(); const entrypoint = getEntrypoint(network); const accountOnNetwork = await entrypoint .createNetworkProvider() .getAccount(account.address); if (denominated > accountOnNetwork.balance) { throw new Error("Not enough EGLD balance"); } account.nonce = accountOnNetwork.nonce; const controller = entrypoint.createTransfersController(); const transaction = await controller.createTransactionForTransfer( account, account.nonce, { receiver: receiverAddress, nativeAmount: denominated, } ); const hash = await entrypoint.sendTransaction(transaction); const explorer = getExplorerUrl(network); return { content: [ { type: "text", text: `${amount} EGLD have been sent to ${receiverAddress.toBech32()}. Check out the transaction here: ${explorer}/transactions/${hash}`, }, ], }; } export const sendEgldToolName = "send-egld"; export const sendEgldToolDescription = "Create a move balance transaction and send it. Will send EGLD using the wallet set in the env to the specified receiver."; export const sendEgldParamScheme = { amount: z .string() .describe( "The amount of EGLD to send. This amount will then be denominated (1 EGLD=1000000000000000000)" ), receiver: z.string().describe("The bech32 address of the receiver (erd1...)"), };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/multiversx/mx-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server