Skip to content

KMD Client

← Back to Examples Overview

Key Management Daemon operations for wallet and key management.

ExampleDescription
KMD Version Information

This example demonstrates how to retrieve version information from the KMD (Key Management Daemon) server using the version() method.

Prerequisites:

Wallet Creation and Listing

This example demonstrates how to create, list, rename, and get info about wallets using the KMD (Key Management Daemon) client.

Prerequisites:

Covered operations:

  • create_wallet() - Create a new wallet
  • list_wallets() - List all available wallets
  • wallet_info() - Get detailed wallet information (requires wallet handle)
  • rename_wallet() - Rename an existing wallet
Wallet Session Management

This example demonstrates how to manage wallet sessions using KMD handle tokens. Handle tokens are used to unlock wallets and perform operations on them. They have an expiration time and should be released when no longer needed.

Prerequisites:

Covered operations:

  • init_wallet_handle() - Unlock a wallet and get a handle token
  • wallet_info() - Check token expiration time (expires_seconds)
  • renew_wallet_handle() - Extend token validity
  • release_wallet_handle() - Invalidate the token
Key Generation

This example demonstrates how to generate new keys in a wallet using the KMD generate_key() method. Keys are generated deterministically from the wallet’s master derivation key, which means they can be recovered if you have the wallet’s mnemonic or master derivation key.

Prerequisites:

Covered operations:

  • generate_key() - Generate a new key in the wallet
  • list_keys() - List all keys in the wallet
Key Import and Export

This example demonstrates how to import and export keys using the KMD import_key() and export_key() methods.

Key concepts:

  • Importing externally generated keys into a wallet
  • Exporting private keys from a wallet
  • Understanding that imported keys are NOT backed up by the master derivation key

Prerequisites:

Covered operations:

  • import_key() - Import an external private key into the wallet
  • export_key() - Export a private key from the wallet
Key Listing and Deletion

This example demonstrates how to list all keys in a wallet and delete specific keys using the KMD list_keys() and delete_key() methods.

Prerequisites:

Covered operations:

  • list_keys() - List all keys (addresses) in a wallet
  • delete_key() - Delete a specific key from the wallet
Master Key Export

This example demonstrates how to export the master derivation key (MDK) for wallet backup using the KMD export_master_key() method.

Key concepts:

  • The master derivation key (MDK) is the root key used to deterministically

generate all keys in the wallet

  • With the MDK, you can recreate a wallet and regenerate all derived keys
  • Imported keys CANNOT be recovered from the MDK
  • The MDK should be stored securely as it can regenerate all wallet keys

Prerequisites:

Covered operations:

  • export_master_key() - Export the master derivation key from a wallet
Multisig Account Setup

This example demonstrates how to create multisig accounts using the KMD import_multisig() method.

Key concepts:

  • A multisig account requires M-of-N signatures to authorize transactions
  • The threshold (M) is the minimum number of signatures required
  • The public keys (N) are the participants who can sign
  • The multisig version parameter (currently always 1) defines the format
  • The resulting multisig address is deterministically derived from the

public keys, threshold, and version

Prerequisites:

Covered operations:

  • generate_key() - Generate keys to use as multisig participants
  • import_multisig() - Create a multisig account from public keys
Multisig Account Management

This example demonstrates how to manage multisig accounts using KMD:

  • list_multisig() - List all multisig accounts in a wallet
  • export_multisig() - Get the multisig preimage information
  • delete_multisig() - Remove a multisig account from the wallet

Key concepts:

  • Multisig accounts can be listed to see all multisigs in a wallet
  • The multisig preimage contains the original parameters: publicKeys, threshold, version
  • Deleting a multisig only removes it from the wallet, not from the blockchain
  • Funds in a deleted multisig address remain on the blockchain

Prerequisites:

Covered operations:

  • generate_key() - Generate keys to use as multisig participants
  • import_multisig() - Create a multisig account from public keys
  • list_multisig() - List all multisig accounts in the wallet
  • export_multisig() - Export the multisig preimage (configuration)
  • delete_multisig() - Delete a multisig account from the wallet
Transaction Signing with KMD

This example demonstrates how to sign transactions using the KMD sign_transaction() method. It shows the complete workflow of creating a wallet, generating a key, funding it, signing a transaction, and submitting it to the network.

Prerequisites:

Covered operations:

  • sign_transaction() - Sign a transaction using a key from the wallet
Multisig Transaction Signing with KMD

This example demonstrates how to sign multisig transactions using the KMD sign_multisig_transaction() method. It shows:

  • Creating a multisig account with 2-of-3 threshold
  • Funding the multisig account via the dispenser
  • Creating a payment transaction from the multisig account
  • Signing with the first participant (partial signature)
  • Signing with the second participant (completing the multisig)
  • Submitting the fully signed transaction to the network

Prerequisites:

Covered operations:

  • sign_multisig_transaction() - Sign a multisig transaction with a participant key
Program Signing (Delegated Logic Signatures) with KMD

This example demonstrates how to sign programs/contracts using the KMD sign_program() method. It shows:

  • Creating a simple TEAL program (logic signature)
  • Compiling the TEAL program using algod’s teal_compile
  • Signing the compiled program bytes with sign_program()
  • Understanding the resulting signature for delegated logic signatures
  • How to use the signature with a LogicSigAccount

What is Program Signing? Program signing creates a “delegated logic signature” (delegated lsig). This allows an account holder to authorize a smart contract (TEAL program) to sign transactions on their behalf. When you sign a program: 1. You’re attesting that you authorize this program to act for your account 2. Transactions signed by this delegated lsig will be authorized by your account 3. The program logic determines which transactions are approved

Use cases for delegated logic signatures:

  • Recurring payments (program checks amount and frequency)
  • Subscription services (program validates payment recipients)
  • Limited spending authorizations (program enforces constraints)
  • Conditional transfers (program checks external conditions)

Prerequisites:

Covered operations:

  • sign_program() - Sign a compiled TEAL program with a wallet key
Multisig Program Signing (Delegated Multisig Logic Signatures) with KMD

This example demonstrates how to sign programs with multisig using the KMD sign_multisig_program() method. It shows:

  • Creating a 2-of-3 multisig account
  • Creating a simple TEAL program (logic signature)
  • Compiling the TEAL program using algod teal_compile
  • Signing the program with the first participant (partial signature)
  • Signing the program with the second participant (completing the multisig)
  • Understanding delegated multisig logic signatures

What is Multisig Program Signing? Multisig program signing creates a “delegated multisig logic signature”. This combines two powerful concepts: 1. Multisig: Requiring multiple parties to approve 2. Delegated Logic Signatures: Authorizing a program to act on behalf of an account

With a delegated multisig lsig:

  • The multisig account authorizes a program to sign transactions
  • Multiple parties must sign the program (meeting the threshold)
  • Once signed, the program can authorize transactions within its logic
  • No further interaction needed from the multisig participants

Use cases for delegated multisig logic signatures:

  • Multi-party controlled recurring payments
  • Joint account automation (e.g., business partners authorizing limit)
  • Escrow with automated release conditions
  • DAO treasury with programmatic spending rules

Prerequisites:

Covered operations:

  • sign_multisig_program() - Sign a compiled TEAL program with a multisig participant

Run any example from the repository’s examples directory:

Terminal window
cd examples
uv run python kmd_client/01_version.py