get_address_from_private_key
Retrieve the EVM address from a private key using this tool on the bnbchain-mcp server. Input a private key in hex format for secure address derivation.
Instructions
Get the EVM address derived from a private key
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| privateKey | No | Private key in hex format (with or without 0x prefix). SECURITY: This is used only for address derivation and is not stored. | 0x5a2b7e4d9c8f1a3e6b0d2c5f4e3d2a1b0c9f8e7d6a5b4c3d2e1f0a9b8c7d6e5f4 |
Implementation Reference
- src/evm/modules/wallet/tools.ts:17-32 (handler)Handler function that formats the input private key (ensuring 0x prefix) and delegates to the service to derive the EVM address.async ({ privateKey }) => { try { // Ensure the private key has 0x prefix const formattedKey = privateKey.startsWith("0x") ? (privateKey as Hex) : (`0x${privateKey}` as Hex) const address = services.getAddressFromPrivateKey(formattedKey) return mcpToolRes.success({ address }) } catch (error) { return mcpToolRes.error(error, "deriving address from private key") } }
- src/evm/modules/wallet/tools.ts:12-33 (registration)Registers the 'get_address_from_private_key' tool on the MCP server with description, input schema, and handler."get_address_from_private_key", "Get the EVM address derived from a private key", { privateKey: privateKeyParam }, async ({ privateKey }) => { try { // Ensure the private key has 0x prefix const formattedKey = privateKey.startsWith("0x") ? (privateKey as Hex) : (`0x${privateKey}` as Hex) const address = services.getAddressFromPrivateKey(formattedKey) return mcpToolRes.success({ address }) } catch (error) { return mcpToolRes.error(error, "deriving address from private key") } } )
- Zod schema definition for the privateKey input parameter used in the tool schema.export const privateKeyParam = z .string() .describe( "Private key in hex format (with or without 0x prefix). SECURITY: This is used only for address derivation and is not stored. The private key will not be logged or displayed in chat history." ) .default(process.env.PRIVATE_KEY as string)
- src/evm/services/clients.ts:66-69 (helper)Core utility function that derives an EVM address from a private key using viem's privateKeyToAccount.export function getAddressFromPrivateKey(privateKey: Hex): Address { const account = privateKeyToAccount(privateKey) return account.address }