<pre><code>import cryptotools

# Set up the mnemonic and derivation path
mnemonic = &quot;your mnemonic goes here&quot;
path = &quot;m/0'&quot;

# Derive the private key and public key from the mnemonic and path
private_key = cryptotools.bip32.master_key(mnemonic.encode())
derived_private_key = private_key / path
public_key = derived_private_key.public_key()

# Generate the SegWit address from the public key
segwit_address = cryptotools.bech32.encode(&quot;bc&quot;, 0, cryptotools.hash160(public_key.to_bytes()))

print(segwit_address)
</code></pre>
<p>Note that this code assumes that you have already installed the cryptotools library using pip. Also, make sure to replace &quot;your mnemonic goes here&quot; with your actual mnemonic phrase, and &quot;m/0'&quot; with the actual derivation path you want to use.</p>
<p>As for disabling wallet saving in BitcoinLib, you can set the BitcoinSecret.Saving property to false to prevent the wallet from being saved to disk. Here is an example code snippet:</p>
<pre><code>BitcoinSecret secret = new BitcoinSecret(&quot;your private key goes here&quot;);
secret.Saving = false;
</code></pre>
<p>Again, replace &quot;your private key goes here&quot; with your actual private key. This code assumes that you have already installed and imported the NBitcoin library, which BitcoinLib is based on.</p>

CC BY-SA 4.0
2023-03-05T20:39:29.973Z
Stop using ChatGPT, ill report this.
cloudzik
CC BY-SA 4.0
2023-03-05T16:34:43.870Z
2023-03-14T11:19:09.637Z
2023-03-14T11:19:09.637Z
santa rio
<p>I am having trouble creating SegWit address from mnemonic. I can't find any useful code to do that. I tried using BitcoinLib but I don't know how to disable saving wallets to disk.</p>
<p><strong>EDIT:</strong>
I found solution that I was looking for. It now shows correct wallet on TrustWallet and on my PC. I used <code>cryptotools</code> libary. Here is the code:</p>
<pre><code>from cryptotools.BTC import Xprv
m = Xprv.from_mnemonic('... mnemonic ...')
print((m/84./0./0./0/0).address('P2WPKH'))
</code></pre>

CC BY-SA 4.0
2023-03-05T13:01:28.397Z
check out https://github.com/mcdallas/cryptotools
Mike D
CC BY-SA 4.0
2023-03-05T14:58:54.807Z
thanks, will check it out and let you know if it worked.
cloudzik
CC BY-SA 4.0
2023-03-05T15:57:31.607Z
Fixed, thank you so much
cloudzik
CC BY-SA 4.0
2023-03-14T13:06:56.620Z
@cloudzik: If you answered your own question can you post an answer rather than answering it in the question? Thanks
Michael Folkson
<segregated-witness><python><python-bitcoinlib>
How to create SegWit address from mnemonic in Python 3.8.10
cloudzik
# How to create SegWit address from mnemonic in Python 3.8.10

(Asked by: username_0 on 2023-03-05)

I am having trouble creating SegWit address from mnemonic. I can't find any useful code to do that. I tried using BitcoinLib but I don't know how to disable saving wallets to disk.
EDIT:
I found solution that I was looking for. It now shows correct wallet on TrustWallet and on my PC. I used cryptotools libary. Here is the code:
from cryptotools.BTC import Xprv
m = Xprv.from_mnemonic('... mnemonic ...')
print((m/84./0./0./0/0).address('P2WPKH'))

**Tags:** segregated-witness, python, python-bitcoinlib

> **Comments:**
> **username_1**: check out https://github.com/mcdallas/cryptotools  
> **username_0**: thanks, will check it out and let you know if it worked.  
> **username_0**: Fixed, thank you so much  
> **username_2**: @username_0: If you answered your own question can you post an answer rather than answering it in the question? Thanks  

---

## 1 answers

### Answer by username_3 on 2023-03-05. Score: -1

import cryptotools

# Set up the mnemonic and derivation path
mnemonic = "your mnemonic goes here"
path = "m/0'"

# Derive the private key and public key from the mnemonic and path
private_key = cryptotools.bip32.master_key(mnemonic.encode())
derived_private_key = private_key / path
public_key = derived_private_key.public_key()

# Generate the SegWit address from the public key
segwit_address = cryptotools.bech32.encode("bc", 0, cryptotools.hash160(public_key.to_bytes()))

print(segwit_address)

Note that this code assumes that you have already installed the cryptotools library using pip. Also, make sure to replace "your mnemonic goes here" with your actual mnemonic phrase, and "m/0'" with the actual derivation path you want to use.
As for disabling wallet saving in BitcoinLib, you can set the BitcoinSecret.Saving property to false to prevent the wallet from being saved to disk. Here is an example code snippet:
BitcoinSecret secret = new BitcoinSecret("your private key goes here");
secret.Saving = false;

Again, replace "your private key goes here" with your actual private key. This code assumes that you have already installed and imported the NBitcoin library, which BitcoinLib is based on.

> **Comments:**
> **username_0**: Stop using ChatGPT, ill report this.  

---

