Skip to main content
Glama

generate_key

Create a new Bitcoin key pair and address for secure cryptocurrency transactions and wallet setup.

Instructions

Generate a new Bitcoin key pair and address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'generate_key' tool. It calls BitcoinService.generateKey() and formats the response as MCP TextContent.
    export async function handleGenerateKey(bitcoinService: BitcoinService) {
      const key = await bitcoinService.generateKey();
      return {
        content: [
          {
            type: "text",
            text: `Generated new Bitcoin key pair:\nAddress: ${key.address}\nPrivate Key (WIF): ${key.privateKey}\nPublic Key: ${key.publicKey}`,
          },
        ] as TextContent[],
      };
    }
  • Registration of the 'generate_key' tool in the ListToolsRequestSchema handler, including name, description, and empty input schema.
    {
      name: "generate_key",
      description: "Generate a new Bitcoin key pair and address",
      inputSchema: { type: "object", properties: {}, required: [] },
    } as Tool,
  • Dispatch logic in the CallToolRequestSchema handler that routes 'generate_key' calls to handleGenerateKey.
    case "generate_key": {
      return handleGenerateKey(this.bitcoinService);
    }
  • Core implementation of key generation using bitcoinjs-lib, producing address, WIF private key, and hex public key.
    async generateKey(): Promise<GeneratedKey> {
      try {
        const keyPair = ECPair.makeRandom({ rng });
        const { address } = bitcoin.payments.p2pkh({
          pubkey: keyPair.publicKey,
          network: this.network,
        });
    
        if (!address) {
          throw new Error("Failed to generate address");
        }
    
        return {
          address,
          privateKey: keyPair.toWIF(),
          publicKey: keyPair.publicKey.toString("hex"),
        };
      } catch (error) {
        logger.error({ error }, "Failed to generate key");
        throw new BitcoinError(
          "Failed to generate key pair",
          BitcoinErrorCode.KEY_GENERATION_ERROR
        );
      }
    }

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/AbdelStark/bitcoin-mcp'

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