import_wallet
Import an existing Solana wallet using a private key or mnemonic phrase to manage assets and interact with the blockchain.
Instructions
Import an existing wallet from private key or mnemonic
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name for the wallet | |
| privateKey | Yes | Private key in base58 format |
Implementation Reference
- src/index.ts:547-569 (handler)The handler function for the 'import_wallet' tool. It extracts name and privateKey from arguments, checks if wallet name exists, decodes the base58-encoded private key to create a Keypair, stores the wallet in the global wallets map, and returns the wallet details on success or throws an error on failure.async function handleImportWallet(args: any) { const { name, privateKey } = args; if (wallets.has(name)) { throw new Error(`Wallet with name '${name}' already exists`); } try { const secretKey = bs58.decode(privateKey); const keypair = Keypair.fromSecretKey(secretKey); wallets.set(name, { keypair, name }); return { success: true, wallet: { name, address: keypair.publicKey.toString() } }; } catch (error) { throw new Error(`Invalid private key: ${error}`); } }
- src/index.ts:89-104 (schema)The input schema definition for the 'import_wallet' tool, specifying required parameters: name (string) and privateKey (base58 string). Part of the tools array used for tool listing.name: "import_wallet", description: "Import an existing wallet from private key or mnemonic", inputSchema: { type: "object", properties: { name: { type: "string", description: "Name for the wallet" }, privateKey: { type: "string", description: "Private key in base58 format" } }, required: ["name", "privateKey"] }
- src/index.ts:1288-1290 (registration)The switch case in the main CallToolRequestSchema handler that registers and dispatches calls to the 'import_wallet' handler function.case "import_wallet": result = await handleImportWallet(args); break;