import_wallet
Import an existing wallet into the Rootstock MCP Server using a private key or mnemonic phrase, with an optional name for wallet management.
Instructions
Import an existing wallet using private key or mnemonic phrase
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "import_wallet"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mnemonic | No | Mnemonic phrase to import (alternative to private key) | |
| name | No | Optional name for the wallet | |
| privateKey | No | Private key to import (alternative to mnemonic) |
Implementation Reference
- src/index.ts:586-600 (handler)MCP tool handler for 'import_wallet': delegates to WalletManager.importWallet and returns formatted success response with wallet address.
private async handleImportWallet(params: ImportWalletParams) { const walletInfo = this.walletManager.importWallet( params.privateKey, params.mnemonic, params.name ); return { content: [ { type: 'text', text: `Wallet imported successfully!\n\nAddress: ${walletInfo.address}`, }, ], }; } - src/index.ts:178-198 (registration)Registers the 'import_wallet' tool in the MCP server's tool list with description and JSON schema for inputs.
{ name: 'import_wallet', description: 'Import an existing wallet using private key or mnemonic phrase', inputSchema: { type: 'object', properties: { privateKey: { type: 'string', description: 'Private key to import (alternative to mnemonic)', }, mnemonic: { type: 'string', description: 'Mnemonic phrase to import (alternative to private key)', }, name: { type: 'string', description: 'Optional name for the wallet', }, }, }, }, - src/types.ts:112-116 (schema)TypeScript interface defining input parameters for import_wallet tool (privateKey, mnemonic, name).
export interface ImportWalletParams { privateKey?: string; mnemonic?: string; name?: string; } - src/wallet-manager.ts:86-118 (helper)Core wallet import logic: creates ethers.Wallet from privateKey or validated mnemonic, stores in manager, sets as current if first.
importWallet(privateKey?: string, mnemonic?: string, _name?: string): WalletInfo { try { let wallet: ethers.Wallet | ethers.HDNodeWallet; if (privateKey) { wallet = new ethers.Wallet(privateKey); } else if (mnemonic) { if (!bip39.validateMnemonic(mnemonic)) { throw new Error('Invalid mnemonic phrase'); } wallet = ethers.Wallet.fromPhrase(mnemonic); } else { throw new Error('Either private key or mnemonic must be provided'); } // Store the wallet this.wallets.set(wallet.address.toLowerCase(), wallet); // Set as current wallet if it's the first one if (!this.currentWallet) { this.currentWallet = wallet.address.toLowerCase(); } return { address: wallet.address, privateKey: wallet.privateKey, mnemonic, publicKey: 'publicKey' in wallet ? (wallet as any).publicKey : undefined, }; } catch (error) { throw new Error(`Failed to import wallet: ${error}`); } }