Skip to main content
Glama

generateWallet

Create and manage Ethereum wallets on the MCP Ethers Wallet server. Optionally save the private key to the server's environment variables for secure, future use.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
saveToEnvNoOptional. If true, the private key will be saved to the server's environment variables for future use. Default is false.

Implementation Reference

  • The handler function generates a random Ethereum wallet using ethers.Wallet.createRandom(). If saveToEnv is true, it saves the private key to process.env and updates the ethersService with a new signer. Returns the wallet address and private key in a formatted text response, or an error response.
    async ({ saveToEnv = false }) => { try { const wallet = ethers.Wallet.createRandom(); if (saveToEnv) { process.env.WALLET_PRIVATE_KEY = wallet.privateKey; // Update the ethersService with the new wallet const signer = new ethers.Wallet(wallet.privateKey, ethersService.provider); ethersService.setSigner(signer); } return { content: [{ type: "text", text: ` New wallet generated: Address: ${wallet.address} Private Key: ${wallet.privateKey} ${saveToEnv ? "Private key has been saved to environment variables for this session." : ""} ` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error generating wallet: ${error instanceof Error ? error.message : String(error)}` }] }; } }
  • Zod input schema defining the optional saveToEnv boolean parameter.
    { saveToEnv: z.boolean().optional().describe( "Optional. If true, the private key will be saved to the server's environment variables for future use. Default is false." ) },
  • Registration of the generateWallet tool using server.tool(), including name, schema, and inline handler function within registerCoreTools.
    server.tool( "generateWallet", { saveToEnv: z.boolean().optional().describe( "Optional. If true, the private key will be saved to the server's environment variables for future use. Default is false." ) }, async ({ saveToEnv = false }) => { try { const wallet = ethers.Wallet.createRandom(); if (saveToEnv) { process.env.WALLET_PRIVATE_KEY = wallet.privateKey; // Update the ethersService with the new wallet const signer = new ethers.Wallet(wallet.privateKey, ethersService.provider); ethersService.setSigner(signer); } return { content: [{ type: "text", text: ` New wallet generated: Address: ${wallet.address} Private Key: ${wallet.privateKey} ${saveToEnv ? "Private key has been saved to environment variables for this session." : ""} ` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error generating wallet: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
  • Call to registerCoreTools within registerAllTools, which registers the generateWallet tool among core tools.
    registerCoreTools(server, ethersService);
  • src/mcpServer.ts:51-51 (registration)
    Top-level call to registerAllTools on the MCP server instance, which chains to core tools registration including generateWallet.
    registerAllTools(server, ethersService);

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/crazyrabbitLTC/mcp-ethers-server'

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