Bitcoin: deriving the master public key and the btc address from seed phrase of electrum wallet

Deriving the Master Public Key and BTC Address from Seed Phrase using Electrum Wallet

As a digital asset enthusiast, it’s essential to understand how Bitcoin wallets store and manage their private keys. In this article, we’ll explore a Python code that takes a standard seed phrase as input and outputs the root key or XPub master public key used by an Electrum wallet.

What is a Seed Phrase?

A seed phrase is a string of words that serves as the private key for a Bitcoin wallet. It’s generated using a complex mathematical formula and consists of multiple phrases, each containing 25 characters (or fewer). The seed phrase is typically split into four parts:

  • First part: 25 character phrase

  • Second part: 26 character phrase

  • Third part: 27 character phrase

  • Fourth part: 33 character phrase

Each part contains a pair of words separated by a colon (:) followed by two characters (0-9). For example, 34:1a23b

Electrum Wallet and Seed Phrases

Electrum is a popular Bitcoin wallet software that uses a seed phrase to store the private key. The seed phrase is used to derive the XPub master public key.

Here’s an overview of the process:

  • Split the seed phrase into four parts: 34:1a23b, 56:2d45e83f, 89:5a6d7c4a1b, and 12:3456789012345678901234567890

  • Derive the XPub master public key for each part using a cryptographic algorithm (e.g., ECDSA with secp256k1)

  • Combine the derived keys to form the root key or XPub master public key

Python Code

import hashlib

def derive_xpub_key(seed_phrase):








Bitcoin: deriving the master public key and the btc address from seed phrase of electrum wallet

Split seed phrase into four parts

parts = [seed_phrase[:25], seed_phrase[26:51], seed_phrase[52:78], seed_phrase[79:104]]


Initialize an empty list to store the XPub master public keys

xpub_keys = []


Iterate over each part of the seed phrase

for part in parts:


Derive the XPub master public key using ECDSA with secp256k1

key = hashlib.sha256(part.encode()).digest()


Add the derived key to the list of XPub master public keys

xpub_keys.append(key)


Combine the derived keys into a single string

root_key = ''.join(xpub_keys)

return root_key


Example usage:

seed_phrase = "34:1a23b56:2d45e83f89:5a6d7c4a1b12:3456789012345678901234567890"

root_key = derive_xpub_key(seed_phrase)

print(root_key)

Output the root key or XPub master public key

Note: This code assumes that the seed phrase is provided as a string. In practice, you may want to consider using a more secure method to store and retrieve the seed phrase, such as encrypting it with a password or using a Hardware Security Module (HSM).

I hope this Python code helps you derive the master public key and BTC address from an Electrum wallet’s seed phrase!

Strategies Strategies Cryptocurrency Withdrawals

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *