import_wallet
Import an existing wallet using a private key for session-based access to coordinated trading operations on Base.
Instructions
Import an existing wallet by private key. Key is stored in-memory for session only.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| private_key | Yes | Private key to import (hex, with or without 0x prefix) | |
| label | No | Optional name/label for the wallet |
Implementation Reference
- src/index.ts:197-230 (handler)The `handleImportWallet` function takes a private key and optional label, creates an ethers Wallet instance, ensures it is not a duplicate, and adds it to the managed `wallets` array.
async function handleImportWallet( args: z.infer<typeof ImportWalletSchema> ): Promise<string> { let key = args.private_key; if (!key.startsWith("0x")) key = "0x" + key; try { const w = new ethers.Wallet(key); const label = args.label || `imported-${wallets.length + 1}`; // Check for duplicates if (wallets.some((mw) => mw.address.toLowerCase() === w.address.toLowerCase())) { return JSON.stringify({ success: false, error: "Wallet already exists in pool" }); } wallets.push({ address: w.address, privateKey: w.privateKey, label, }); return JSON.stringify( { success: true, address: w.address, label, total_managed: wallets.length, }, null, 2 ); } catch { return JSON.stringify({ success: false, error: "Invalid private key" }); } - src/index.ts:113-116 (schema)The `ImportWalletSchema` defines the expected input format for the `import_wallet` tool using Zod, requiring a `private_key` string and an optional `label`.
const ImportWalletSchema = z.object({ private_key: z.string().describe("Private key to import (hex, with or without 0x prefix)"), label: z.string().optional().describe("Optional name/label for the wallet"), }); - src/index.ts:776-785 (registration)The `import_wallet` tool is registered in the tool list, providing its name, description, and input schema reference.
name: "import_wallet", description: "Import an existing wallet by private key. Key is stored in-memory for session only.", inputSchema: { type: "object" as const, properties: { private_key: { type: "string", description: "Private key to import (hex, with or without 0x prefix)", },