Skip to main content
Glama

Aptos Blockchain MCP

fundAccount.ts3.81 kB
import { Tool } from "@modelcontextprotocol/sdk/types.js"; import { getAptosClient, isTestnet } from "../../config.js"; import { formatAPT, formatAddress } from "../../utils/format.js"; export const FUND_ACCOUNT: Tool = { name: "fund_account", description: "Fund an Aptos account using the testnet faucet. This is only available on testnet and is used to add APT tokens to an account for testing purposes. Returns the funding transaction details.", inputSchema: { type: "object", properties: { account_address: { type: "string", description: "Aptos account address to fund, e.g., 0x1 or 0x742d35Cc6634C0532925a3b8D6Ac0C4db9c8b3", }, amount: { type: "number", description: "Amount of APT to fund (optional, defaults to 1 APT)", default: 1, }, }, required: ["account_address"], }, }; /** * Funds an Aptos account using the testnet faucet * @param args The arguments containing the account address and optional amount * @returns The funding transaction details */ export async function fundAccountHandler(args: Record<string, any> | undefined) { if (!isFundAccountArgs(args)) { throw new Error("Invalid arguments for fund_account"); } const { account_address, amount = 1 } = args; try { const results = await performFundAccount(account_address, amount); return { content: [{ type: "text", text: results }], isError: false, }; } catch (error) { return { content: [ { type: "text", text: `Error funding account: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } /** * Funds an Aptos account using the testnet faucet * @param accountAddress The Aptos account address to fund * @param amount The amount of APT to fund * @returns The funding transaction details as a formatted string */ export async function performFundAccount(accountAddress: string, amount: number = 1): Promise<string> { try { if (!isTestnet()) { throw new Error("Account funding is only available on testnet"); } const aptos = getAptosClient(); // Convert APT to Octas (1 APT = 10^8 Octas) const amountOctas = Math.floor(amount * 100000000); // Fund the account using the faucet const txns = await aptos.fundAccount({ accountAddress, amount: amountOctas, }); // Get the first transaction hash const txHash = Array.isArray(txns) ? txns[0] : txns; return `Account Funding Successful: Account: ${formatAddress(accountAddress)} Amount: ${amount} APT (${amountOctas} Octas) Transaction Hash: ${txHash} ✅ Account has been funded and is ready for transactions!`; } catch (error) { console.error('Error funding account:', error); if (error instanceof Error) { if (error.message.includes('faucet')) { throw new Error("Faucet service is unavailable. Please try again later or use a different faucet."); } if (error.message.includes('rate limit')) { throw new Error("Faucet rate limit exceeded. Please wait before requesting more funds."); } } throw new Error(`Failed to fund account: ${error instanceof Error ? error.message : String(error)}`); } } /** * Checks if the provided arguments are valid for the fundAccount tool * @param args The arguments to check * @returns True if the arguments are valid, false otherwise */ export function isFundAccountArgs(args: unknown): args is { account_address: string; amount?: number } { return ( typeof args === "object" && args !== null && "account_address" in args && typeof (args as any).account_address === "string" && (!(args as any).amount || typeof (args as any).amount === "number") ); }

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/punkpeye/aptos-mcp'

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