Skip to main content
Glama

generateWallet

Create a new Ethereum wallet with a private key, optionally saving it to environment variables for secure access in blockchain operations.

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

  • Full registration of the generateWallet MCP tool, including Zod input schema, async handler function that creates a random Ethereum wallet using ethers.Wallet.createRandom(), optionally saves private key to env, and returns address and private key.
    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)}` }] }; } } );
  • Zod schema for generateWallet tool input: optional boolean saveToEnv.
    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." )
  • Handler function for generateWallet tool: generates random wallet, optionally persists to env and updates service, returns formatted 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)}` }] }; } }
  • Registration of core tools group (including generateWallet) via registerCoreTools call in top-level tools index.
    registerCoreTools(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