wallet_get_address
Retrieve the wallet address from a provided private key, mnemonic, or JSON. Automatically uses the PRIVATE_KEY environment variable if no input is given.
Instructions
Get the wallet address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| wallet | No | The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set. |
Implementation Reference
- src/handlers/wallet.ts:180-191 (handler)The core handler function for 'wallet_get_address' that fetches the wallet using the getWallet helper and returns its address.export const getAddressHandler = async (input: any): Promise<ToolResultSchema> => { try { const wallet = await getWallet(input.wallet); return createSuccessResponse( `Wallet address retrieved successfully: Address: ${wallet.address} `); } catch (error) { return createErrorResponse(`Failed to get wallet address: ${(error as Error).message}`); } };
- src/tools.ts:142-151 (schema)Input schema definition for the wallet_get_address tool in the tools array.name: "wallet_get_address", description: "Get the wallet address", inputSchema: { type: "object", properties: { wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." } }, required: [] } },
- src/tools.ts:567-567 (registration)Registration of the getAddressHandler function to the 'wallet_get_address' tool name in the handlers dictionary."wallet_get_address": getAddressHandler,
- src/handlers/utils.ts:74-114 (helper)Supporting utility getWallet that constructs the ethers.Wallet from input string (private key, mnemonic, or encrypted JSON), connects to provider, and handles env var fallback. Critical for the handler's logic.export const getWallet = async ( walletData?: string, password?: string, ): Promise<ethers.Wallet> => { const provider = getProvider() // If walletData is not provided, check for PRIVATE_KEY environment variable if (!walletData && process.env.PRIVATE_KEY) { const wallet = new ethers.Wallet(process.env.PRIVATE_KEY); return provider ? wallet.connect(provider) : wallet; } // If no walletData and no environment variable, throw an error if (!walletData) { throw new Error("Wallet data is required or set PRIVATE_KEY environment variable"); } try { // Try to parse as JSON first if (walletData.startsWith("{")) { if (!password) { throw new Error("Password is required for encrypted JSON wallets"); } const wallet = await ethers.Wallet.fromEncryptedJson(walletData, password); return provider ? wallet.connect(provider) : wallet; } // Check if it's a mnemonic (12, 15, 18, 21, or 24 words) const words = walletData.trim().split(/\s+/); if ([12, 15, 18, 21, 24].includes(words.length)) { const wallet = ethers.Wallet.fromMnemonic(walletData); return provider ? wallet.connect(provider) : wallet; } // Assume it's a private key const wallet = new ethers.Wallet(walletData); return provider ? wallet.connect(provider) : wallet; } catch (error) { throw new Error(`Invalid wallet data: ${(error as Error).message}`); } };