fund_account
Add APT tokens to an Aptos testnet account using the testnet faucet for testing purposes. Specify the account address and optional amount to fund. Returns transaction details.
Instructions
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.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_address | Yes | Aptos account address to fund, e.g., 0x1 or 0x742d35Cc6634C0532925a3b8D6Ac0C4db9c8b3 | |
| amount | No | Amount of APT to fund (optional, defaults to 1 APT) |
Implementation Reference
- src/tools/account/fundAccount.ts:30-54 (handler)The primary handler function for the 'fund_account' tool. It validates the input arguments, calls the performFundAccount helper, and returns a formatted MCP response (success or error).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, }; } }
- The tool specification object defining the name, description, and input schema for the 'fund_account' tool, used for registration and validation.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"], }, };
- Core helper function implementing the account funding logic using the Aptos SDK faucet, including amount conversion, transaction execution, error handling, and formatted success message.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)}`); } }
- src/index.ts:116-117 (registration)Tool registration in the main MCP server switch dispatcher: maps 'fund_account' calls to the fundAccountHandler.case "fund_account": return await fundAccountHandler(args);
- src/http-server.ts:106-107 (registration)Tool registration in the HTTP MCP server switch dispatcher: maps 'fund_account' calls to the fundAccountHandler.case "fund_account": return await fundAccountHandler(args);