Create xPub Key with The Electrum Wallet

This post is also available in: German

How to create an xPub key with the Electrum Wallet

Create xPub Key with The Electrum Wallet

team

What is an Extended Public Keys (xpub Key)?

In an online shop, a new Bitcoin address must be generated for each payment process. This is necessary in order to clearly assign each incoming payment to an order. This requires an Extended Public Keys (xpub).

One can think of the xpub key as a kind of master key from which an almost endless amount of public keys – and thus bitcoin addresses – can be generated.

The counterpart, the Private Key, is the so-called seed, which is often encoded in the form of 12 to 24 words. These words must be kept secure.
The xPub key is a public key that can be passed on easily.

If you accept Bitcoin payments as a merchant, you must deposit this xPub key in your shop so that the shop can present new Bitcoin address to the buyer.

An xPub key can be created with a variety of wallets.
In this article we explain how to create an xPub key with the help of the Electrum Wallet and then deposit it with the BTCPay server.

How to create an xPub key with the Electrum Wallet

The Bitcoin Payment Server operates without an intermediary. This means that the merchant receives the Bitcoin payments directly on his own Bitcoin Wallet.

To do this, the merchant must have its own Bitcoin Wallet. The corresponding Bitcoin addresses to which the customers send the Bitcoin must be stored accordingly with the BTCPay Server.

If you as a merchant have commissioned a programmer, administrator or external service provider to integrate Bitcoin payments into the online shop, you must remain the owner of the private key. Only the owner of the private key is also the owner via the Bitcoin.

In this guide, we’ll explain exactly how to get the Private Key. Even if you are not a computer expert, you should not get any problems with this manual, because you cannot delegate this area, you have to do it yourself.

xPub addresses

With the help of the BTCPay Server, the incoming payments are received and managed. This requires your own Bitcoin wallet. Because the Bitcoin credit is never on the payment server, but always on the wallet of the merchant.

A wallet is required to generate on the basis of xPub public keys. A public key is the Bitcoin address, which is communicated to the payer in order to send the payment there. The xPub key is able to generate an infinite number of Bitcoin addresses. This number is also required for a standalone and independent Bitcoin address to be used for each payment transaction.

This public key (xPub) is stored with the BTCPay Server and the corresponding private key remains in the possession of the trader.

The BTCPay Server is thus able to generate a public key, i.e. a Bitcoin address, for each individual transaction and credit the payments directly to the trader’s Bitcoin wallet.

Extended public keys always start with one of the following prefixes: “xpub”, “ypub” or “zpub”. The first letter, however, indicates what kind of addresses can be generated with each xpub: xpubs becomes legacy addresses, ypubs and zpubs BIP49-compatible P2SH or bech32 addresses with SegWit Support.

P2SH can be seen by the fact that they start with a 3 (unlike legacy addresses that start with a 1 and bech32 start with “bc1”.

Since we need the xPub key for our shop, we use a format that is supported by all wallets. We recommend using segwit p2sh. This Bitcoin address starts with the 3.

Electrum Bitcoin Wallet

A Bitcoin wallet is required to manage the payments in his shop. We recommend the Electrum Wallet for use as a merchant wallet. With the Electrum Wallet, addresses can be generated via xPub and deposited with the BTCPay server.

Of course, other Bitcoin wallets can also be used that can generate Xpub addresses. In this manual, we consider this using the example of the Electrum Wallet, as it is ideally suited for our application.

We install this Bitcoin Wallet on our local workstation.

To this end, we go to the website of http://electrum.org

Please pay close attention to the domain name (Electrum and with the extension .org) and download only the software from this page.

Electrum Bitcoin Wallet

Electrum Bitcoin Wallet

The website is only available in English. We go to the download area and select our operating system.

In most cases, this will be a Mac or a Windows machine.

Electrum Wallet Download

Electrum Wallet Download

Download the software and double-click to start the installation. You will receive alerts from your computer as it is software from the Internet. This is normal. For security reasons, check the exact spelling of the domain again, so that the software is really only loaded from the page electrum.org.

Install Electrum Wallet

After the Electrum Wallet has been installed and started, you should set a wallet name.

This is not necessary at this point, as we will set the name at a later time. That is why we are ignoring the proposal and using the proposed name.

Create xPub Key with The Electrum Wallet 1

The wallet is installed as a default wallet.

Electrum Wallet Standard Wallet

Electrum Wallet Standard Wallet

As a multi-sig wallet, it would be a good thing if you wanted to secure the Bitcoin balance with several keys and people.

If you had already generated a wallet at an earlier time and now want to import an existing private key into the Electrum wallet, you would use the Import Private Key function.

After we have continued with the standard wallet

Electrum Wallet Seed Generation

Electrum Wallet Seed Generation

We choose the “Create a new seed” option and have to choose between Segwit or Legacy on the next page.

As a merchant, it is recommended to use segwit p2sh. Segwit benefits payers from low transaction fees. If we were to use Segwit, the Bitcoin addresses would start with bc1.

However, there are still some wallets from end customers that do not fully support Segwit. In order not to exclude this customer, we recommend using segwit p2sh. This Bitcoin address starts with the 3.

To generate a segwit p2sh address via the Electrum Wallet, we need to choose Lecacy and NOT SegWit when selecting. If we were to select SegWit at this point, we would only be able to offer SegWit and exclude the other wallets.

That’s why we continue with Legacy:

Electrum Wallet legacy

Electrum Wallet legacy

 

After that, a seed phrase is generated from 12 different words. This is almost your private key. You have to keep it safe and don’t tell anyone. If you know these 12 words, you have the Bitcoin on your wallet.

Electrum Walle Seed

Electrum Walle Seed

 

If your work computer breaks or you no longer have access to the server. No problem as long as you know these twelve words.

So write down exactly and store it in a very safe place. Don’t betray anyone. Also not your programmer, administrator or service provider, who integrates the Bitcoin Payment into the shop.

Because these twelve words are so important, you get the blank page displayed

Create xPub Key with The Electrum Wallet 2and you have to enter the 12 words again:

Electrum Seed Confirmation

Electrum Seed Confirmation

Then you click on Next and you will be asked to generate a password.

Abort

Abort

At this point you break off. Not just back, but cancel completely.

You go to Electrum under File and then under New/Restore. You start as if you’re creating a new wallet at Electrum.

You will be asked again what you want to call the wallet. At this point, the name is now set.

For example, we give the wallet the name BTCPayServer

Electrum wallet name

Electrum wallet name

Click Next.

Re-create it as a standard wallet.

Attention: At this point do not import a private key.

Create xPub Key with The Electrum Wallet 3

After that, the following window appears

 

Create xPub Key with The Electrum Wallet 4

and choose here that we already have a seed.

Then we are asked to enter the seed. We now enter the 12 words we generated in the first pass.

Create xPub Key with The Electrum Wallet 5

Then we click on Options. In the window, we activate BIP39 seed and click OK.

GDP39-seed

GDP39-seed

The following page with the security warning appears

Create xPub Key with The Electrum Wallet 6

and click Next.

We select the option with p2sh-segwit (p2wpkh-p2sh)

p2sh-segwit (p2wpkh-p2sh)

p2sh-segwit (p2wpkh-p2sh)

and click Next.

Then you need to remember a secure password to access your wallet.

electrum password

electrum password

An Encrypt wallet file is generated and stored on your computer. The previously generated password is required to decrypt this file. So keep this password secure as well.

You will then arrive at the Electrum Dashboard.

Electrum Dashboard

Electrum Dashboard

Here you have the possibility to send Bitcoin, receive and view the history of your transactions.

Here you can check whether everything has been done correctly. We do this by clicking Receive. If we get a Bitcoin address with a 3 displayed there, it looks very good.

Create xPub Key with The Electrum Wallet 7

Then we click on Addresses and get 10 Bitcoin addresses displayed, which have already been generated:

 

Create xPub Key with The Electrum Wallet 8These addresses also start with a 3.

However, since we assume that more than 10 transactions take place in our shop, we need to increase the number of bitcoin addresses generated in advance.

We do this by switching to the Console section.

Electrum Console

Electrum Console

We read the warning and click on the yellow area.

We want to increase the gap limit to 100. We want to generate a total of 100 Bitcoin addresses in advance.

To do this, we enter the command:

wallet.change_gap_limit(100)

and press Enter.

Electrum Gap Limit

Electrum Gap Limit

After that, we give

wallet.storage.write()

A.

To check how high the new gap limit is now, let’s give the command:

wallet.gap_limit

A.

It’s all right when it looks like this:

Electrum Gap Limit 100

Electrum Gap Limit 100

export xPub key

Now we need the xPub key to store this key in the BTCPay Server. This xPub key is the public key that can be passed on without any problems.

You export the xPub key by switching to the Wallet section and then to Information.

There you will find the xPub Key, referred to as master public key:

p2wpkh-p2sh

p2wpkh-p2sh

If the script type is also p2wpkh-p2sh, then we have done everything correctly.

Now this Xpub key can be used to generate an infinite number of Bitcoin addresses.

We now store this Xpub key in our BTCPay Shop on the BTCPay server.

You can find out how this works in the post: “Deposit ingessing The Xpub Key with the BTCPay Server

This post is also available in: German