Skip to main content
Added information about gap limit and generating more addresses
Source Link
user103136
user103136

An electrum wallet (legacy, testnet)

Electrum-XPUB-Addresses

C# code for below windows application that returns 10 addresses from one XPUB using NBitcoin

var pubkey = ExtPubKey.Parse(textBox1.Text, Network.TestNet);
                    

        for (uint i=0; i < 10; i++)
        {
            var Address = pubkey.Derive(0).Derive(i).PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.TestNet);
            richTextBox1.AppendText(Address.ToString());
            richTextBox1.AppendText("\n");
           
        }

WindowsApp-XPUB

The gap limit is the maximum number of consecutive unused addresses in your deterministic sequence of addresses. Electrum uses it in order to stop looking for addresses. In Electrum, it is set to 20 by default, so the client will get all addresses until 20 unused addresses are found.

Electrum will generate new addresses as you use them, until it hits the gap limit. Addresses beyond the gap limit will not automatically be recovered from the seed. To recover them will require either increasing the client’s gap limit or generating new addresses until the used addresses are found. If you wish to generate more than one address, you can use a “for” loop. For example, if you wanted to generate 50 addresses, you could do this: [wallet.create_new_address(False) for i in range(50)]

https://electrum.readthedocs.io/en/latest/faq.html#gap-limit

If I run the above code with i < 50 in for loop I get 50 addresses from the XPUB

gap-limit-1

Gap limit can be changed with: wallet.change_gap_limit(50)

Now I see 50 addresses instead of 20 (excluding change addresses) in electrum wallet same as returned by the code above:

gap-limit-2

An electrum wallet (legacy, testnet)

Electrum-XPUB-Addresses

C# code for below windows application that returns 10 addresses from one XPUB using NBitcoin

var pubkey = ExtPubKey.Parse(textBox1.Text, Network.TestNet);
                    

        for (uint i=0; i < 10; i++)
        {
            var Address = pubkey.Derive(0).Derive(i).PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.TestNet);
            richTextBox1.AppendText(Address.ToString());
            richTextBox1.AppendText("\n");
           
        }

WindowsApp-XPUB

The gap limit is the maximum number of consecutive unused addresses in your deterministic sequence of addresses. Electrum uses it in order to stop looking for addresses. In Electrum, it is set to 20 by default, so the client will get all addresses until 20 unused addresses are found.

https://electrum.readthedocs.io/en/latest/faq.html#gap-limit

If I run the above code with i < 50 in for loop I get 50 addresses from the XPUB

gap-limit-1

Gap limit can be changed with: wallet.change_gap_limit(50)

Now I see 50 addresses instead of 20 (excluding change addresses) in electrum wallet same as returned by the code above:

gap-limit-2

An electrum wallet (legacy, testnet)

Electrum-XPUB-Addresses

C# code for below windows application that returns 10 addresses from one XPUB using NBitcoin

var pubkey = ExtPubKey.Parse(textBox1.Text, Network.TestNet);
                    

        for (uint i=0; i < 10; i++)
        {
            var Address = pubkey.Derive(0).Derive(i).PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.TestNet);
            richTextBox1.AppendText(Address.ToString());
            richTextBox1.AppendText("\n");
           
        }

WindowsApp-XPUB

The gap limit is the maximum number of consecutive unused addresses in your deterministic sequence of addresses. Electrum uses it in order to stop looking for addresses. In Electrum, it is set to 20 by default, so the client will get all addresses until 20 unused addresses are found.

Electrum will generate new addresses as you use them, until it hits the gap limit. Addresses beyond the gap limit will not automatically be recovered from the seed. To recover them will require either increasing the client’s gap limit or generating new addresses until the used addresses are found. If you wish to generate more than one address, you can use a “for” loop. For example, if you wanted to generate 50 addresses, you could do this: [wallet.create_new_address(False) for i in range(50)]

https://electrum.readthedocs.io/en/latest/faq.html#gap-limit

If I run the above code with i < 50 in for loop I get 50 addresses from the XPUB

gap-limit-1

Gap limit can be changed with: wallet.change_gap_limit(50)

Now I see 50 addresses instead of 20 (excluding change addresses) in electrum wallet same as returned by the code above:

gap-limit-2

Added information about gap limit
Source Link
user103136
user103136

An electrum wallet (legacy, testnet)

Electrum-XPUB-Addresses

C# code for below windows application that returns 10 addresses from one XPUB using NBitcoin

var pubkey = ExtPubKey.Parse(textBox1.Text, Network.TestNet);
                    

        for (uint i=0; i < 10; i++)
        {
            var Address = pubkey.Derive(0).Derive(i).PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.TestNet);
            richTextBox1.AppendText(Address.ToString());
            richTextBox1.AppendText("\n");
           
        }

WindowsApp-XPUB

The gap limit is the maximum number of consecutive unused addresses in your deterministic sequence of addresses. Electrum uses it in order to stop looking for addresses. In Electrum, it is set to 20 by default, so the client will get all addresses until 20 unused addresses are found.

https://electrum.readthedocs.io/en/latest/faq.html#gap-limit

If I run the above code with i < 50 in for loop I get 50 addresses from the XPUB

gap-limit-1

Gap limit can be changed with: wallet.change_gap_limit(50)

Now I see 50 addresses instead of 20 (excluding change addresses) in electrum wallet same as returned by the code above:

gap-limit-2

An electrum wallet (legacy, testnet)

Electrum-XPUB-Addresses

C# code for below windows application that returns 10 addresses from one XPUB using NBitcoin

var pubkey = ExtPubKey.Parse(textBox1.Text, Network.TestNet);
                    

        for (uint i=0; i < 10; i++)
        {
            var Address = pubkey.Derive(0).Derive(i).PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.TestNet);
            richTextBox1.AppendText(Address.ToString());
            richTextBox1.AppendText("\n");
           
        }

WindowsApp-XPUB

An electrum wallet (legacy, testnet)

Electrum-XPUB-Addresses

C# code for below windows application that returns 10 addresses from one XPUB using NBitcoin

var pubkey = ExtPubKey.Parse(textBox1.Text, Network.TestNet);
                    

        for (uint i=0; i < 10; i++)
        {
            var Address = pubkey.Derive(0).Derive(i).PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.TestNet);
            richTextBox1.AppendText(Address.ToString());
            richTextBox1.AppendText("\n");
           
        }

WindowsApp-XPUB

The gap limit is the maximum number of consecutive unused addresses in your deterministic sequence of addresses. Electrum uses it in order to stop looking for addresses. In Electrum, it is set to 20 by default, so the client will get all addresses until 20 unused addresses are found.

https://electrum.readthedocs.io/en/latest/faq.html#gap-limit

If I run the above code with i < 50 in for loop I get 50 addresses from the XPUB

gap-limit-1

Gap limit can be changed with: wallet.change_gap_limit(50)

Now I see 50 addresses instead of 20 (excluding change addresses) in electrum wallet same as returned by the code above:

gap-limit-2

Source Link
user103136
user103136

An electrum wallet (legacy, testnet)

Electrum-XPUB-Addresses

C# code for below windows application that returns 10 addresses from one XPUB using NBitcoin

var pubkey = ExtPubKey.Parse(textBox1.Text, Network.TestNet);
                    

        for (uint i=0; i < 10; i++)
        {
            var Address = pubkey.Derive(0).Derive(i).PubKey.GetAddress(ScriptPubKeyType.Legacy, Network.TestNet);
            richTextBox1.AppendText(Address.ToString());
            richTextBox1.AppendText("\n");
           
        }

WindowsApp-XPUB