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
| Name | Required | Description | Default |
|---|---|---|---|
| saveToEnv | No | Optional. If true, the private key will be saved to the server's environment variables for future use. Default is false. |
Implementation Reference
- src/tools/core.ts:143-175 (handler)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)}` }] }; } }
- src/tools/core.ts:138-142 (schema)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." ) },
- src/tools/core.ts:136-176 (registration)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)}` }] }; } } );
- src/tools/index.ts:23-23 (registration)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);