Skip to main content
Glama

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
NameRequiredDescriptionDefault
privateKeyNoPrivate key in hex format (with or without 0x prefix). SECURITY: This is used only for address derivation and is not stored.0x5a2b7e4d9c8f1a3e6b0d2c5f4e3d2a1b0c9f8e7d6a5b4c3d2e1f0a9b8c7d6e5f4

Implementation Reference

  • 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")
      }
    }
  • 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)
  • 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
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bnb-chain/bnbchain-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server