Skip to main content
Glama

generate_keypair

Generate a new Bitcoin address with your local node's wallet. Choose address types and manage private key visibility for secure transactions.

Instructions

Generate a new Bitcoin address via the connected node's wallet. Requires a local node with a wallet loaded — not available when using the hosted Satoshi API.

SECURITY: Private keys are redacted by default because AI provider tool responses may be logged. Set include_private_key=True only if you understand the risk — the key will appear in your conversation history and should be considered potentially compromised for high-value use.

Args: address_type: Address type — "legacy" (P2PKH), "p2sh-segwit" (P2SH-P2WPKH), "bech32" (P2WPKH, default), or "bech32m" (P2TR taproot) include_private_key: If True, include the WIF private key in the response. Defaults to False for security.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
address_typeNobech32
include_private_keyNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler for the generate_keypair tool, which uses the Bitcoin RPC to generate a new address from a local node.
    def generate_keypair(address_type: str = "bech32", include_private_key: bool = False) -> str:
        """Generate a new Bitcoin address via the connected node's wallet. Requires a local node with a wallet loaded — not available when using the hosted Satoshi API.
    
        SECURITY: Private keys are redacted by default because AI provider tool responses may be logged. Set include_private_key=True only if you understand the risk — the key will appear in your conversation history and should be considered potentially compromised for high-value use.
    
        Args:
            address_type: Address type — "legacy" (P2PKH), "p2sh-segwit" (P2SH-P2WPKH), "bech32" (P2WPKH, default), or "bech32m" (P2TR taproot)
            include_private_key: If True, include the WIF private key in the response. Defaults to False for security.
        """
        try:
            rpc = get_rpc()
            if isinstance(rpc, _SatoshiRPC):
                return json.dumps({
                    "error": "generate_keypair requires a local Bitcoin node with a wallet loaded. "
                             "It is not available when using the hosted Satoshi API.",
                    "hint": "Run Bitcoin Core locally with a wallet, or use a dedicated wallet tool for key generation.",
                })
            address = rpc.getnewaddress("", address_type)
            addr_info = rpc.getaddressinfo(address)
    
            result = {
                "address": address,
                "public_key_hex": addr_info.get("pubkey"),
                "address_type": address_type,
                "is_mine": addr_info.get("ismine", False),
            }
    
            if include_private_key:
                try:
                    privkey = rpc.dumpprivkey(address)
                except Exception:
                    privkey = None  # Watch-only or descriptor wallet without private keys
                result["private_key_wif"] = privkey
                result["security_warning"] = (
                    "This private key is now in your conversation history. "
                    "Store it securely and consider this key potentially compromised for high-value use."
                )
            else:
                result["private_key_wif"] = (
                    "[REDACTED — set include_private_key=true to reveal. "
                    "WARNING: will be visible in conversation history]"
                )
    
            return json.dumps(result)
        except Exception as e:
            hint = _connection_hint(e)
            msg = str(e)
            if "no wallet" in msg.lower() or "wallet" in msg.lower():
                hint = "No wallet loaded. Create or load a wallet first: bitcoin-cli createwallet \"mywallet\""
            return json.dumps({"error": msg, "hint": hint})

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

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