<p>In case you are talking about mnemonic seed use this - </p>

<p>Install bitcore-mnemonic</p>

<pre><code>npm install bitcore-mnemonic
bower install bitcore-mnemonic
</code></pre>

<p>Then use it to generate mnemonic seed - </p>

<pre><code>var Mnemonic = require('bitcore-mnemonic');
var code = new Mnemonic(Mnemonic.Words.ENGLISH);
code.toString(); 
// army van defense carry jealous true garbage claim echo media make crunch...

var xpriv = code.toHDPrivateKey();
</code></pre>

<p>If you just want to generate a private from bitcore api you can use this function - </p>

<pre><code>var bitcore = require('bitcore');
var HDPrivateKey = bitcore.HDPrivateKey;
</code></pre>

<p>Please note there is no rule to generate a private key. A private key is just a random string. It could even be your name or a whole article. But you must create a private key that is 'random' in nature. Also never use programming language functions like md5 hash or something to generate a private key because they are not truly random. </p>

<p>Bitcore api, however, provides an easy way to generate a private key using the above method. From there you can proceed as usual.</p>

<pre><code>var bitcore = require('bitcore');
var HDPrivateKey = bitcore.HDPrivateKey;

var hdPrivateKey = new HDPrivateKey();
var retrieved = new HDPrivateKey('xpriv...');
var derived = hdPrivateKey.derive("m/0'");
var derivedByNumber = hdPrivateKey.derive(1).derive(2, true);
var derivedByArgument = hdPrivateKey.derive("m/1/2'");
assert(derivedByNumber.xprivkey === derivedByArgument.xprivkey);

var address = derived.privateKey.toAddress();

// obtain HDPublicKey
var hdPublicKey = hdPrivateKey.hdPublicKey;
</code></pre>

CC BY-SA 4.0
2018-07-17T05:11:17.143Z
Hi Abhishek, thanks for your answer. Can you please also confirm if mnemonic seed is used at the time of recovering wallets when lost?
Gagan
CC BY-SA 4.0
2018-07-17T05:55:25.220Z
Yes, you can easily use mnemonics, in fact, in any standard wallet like trezor to recover back your funds. Mnemonics are actually created from private keys itself. You can learn about the process here - https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch05.asciidoc 

When you use 
var code = new Mnemonic(Mnemonic.Words.ENGLISH);
bitcore api selects the private key for you and generates the mnemonics from it doing all the hard work for you. So you can think these mnemonics represents your private keys and you can use them to recover your funds.
Abhishek Sinha
CC BY-SA 4.0
2018-07-17T06:39:38.913Z
Glad to help you.  If my answer meets your requirement please mark it as the accepted answer. Thanks
Abhishek Sinha
CC BY-SA 4.0
2018-07-17T07:01:34.863Z
Done! Abhishek, I have a quick question for you. Mnemonic Seed will be created after a new wallet is created. Is that right? And if so, does it mean the created mnemonic seed will represent this wallet? Or do I need to do something to link the seed with my wallet??
Gagan
CC BY-SA 4.0
2018-07-17T07:27:28.353Z
Because as per my research so far, mnemonic is generated from a random string. So I'm confused how it will represent my wallet.
Gagan
CC BY-SA 4.0
2018-07-17T08:49:46.597Z
See the xpriv variable in the above code. It holds a HD private key. From this private key create public keys and addresses. Use only these addresses to transfer funds. So you need to 1. Generate mneomincs 2. Get your private keys from it as shown above. Then once you have HD private keys, generate addresses and HD public keys using the functions scripted in the answer.
Abhishek Sinha
CC BY-SA 4.0
2018-07-17T08:49:58.487Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/80270/discussion-between-abhishek-sinha-and-gagan).
Abhishek Sinha
CC BY-SA 4.0
2018-07-16T13:57:46.453Z
2018-07-16T13:57:46.453Z
Abhishek Sinha
<p>Can someone please explain how to get Master Seed when a new HD keys is created using Bitcore APIs?</p>

<p>My purpose is to implement wallet service in my application using Bitcore APIs.</p>

<p>Refer this link <a href="https://bitcore.io/api/lib/hd-keys" rel="nofollow noreferrer">here</a> </p>

CC BY-SA 4.0
2018-07-16T12:18:25.107Z
Please elaborate your question. Are you asking to derive HD private keys from a newly generated public key or address? If so, it is not possible. Which specific function in Bitcore API you are referring to?
Abhishek Sinha
CC BY-SA 4.0
2018-07-16T12:44:40.393Z
Hi Abhishek, no. I want to implement HD wallets into my application. According to my understanding there must be a master seed for each new wallet. Each wallet is simply a pair of HD private and public key, right? And we can create more public keys(addresses) using HD private key. My question is how will I get this master seed at first place?
Gagan
CC BY-SA 4.0
2018-07-16T13:07:03.357Z
Are you talking about 12 or 24 words mnemonic seed or recovery phrase?
Abhishek Sinha
CC BY-SA 4.0
2018-07-17T05:14:02.623Z
I would really appreciate if you could also mention the difference between them in your answer. I want to give my users master seeds for their wallets so that in future if they lose their wallets they can recover using the master seed they possess.
Gagan
CC BY-SA 4.0
2018-07-17T05:57:31.730Z
Give them the mnemonics. That's enough. They can recover their funds in any standard wallet if they have the mnemonics that represent the correct private keys of their wallet.
Abhishek Sinha
<api><bip32-hd-wallets><seed><bitcore>
How Master seed is generated using Bitcore API?
Gagan
# How Master seed is generated using Bitcore API?

(Asked by: username_0 on 2018-07-16)

Can someone please explain how to get Master Seed when a new HD keys is created using Bitcore APIs?

My purpose is to implement wallet service in my application using Bitcore APIs.

Refer this link [here](https://bitcore.io/api/lib/hd-keys)

**Tags:** api, bip32-hd-wallets, seed, bitcore

> **Comments:**
> **username_1**: Please elaborate your question. Are you asking to derive HD private keys from a newly generated public key or address? If so, it is not possible. Which specific function in Bitcore API you are referring to?  
> **username_0**: Hi username_1, no. I want to implement HD wallets into my application. According to my understanding there must be a master seed for each new wallet. Each wallet is simply a pair of HD private and public key, right? And we can create more public keys(addresses) using HD private key. My question is how will I get this master seed at first place?  
> **username_1**: Are you talking about 12 or 24 words mnemonic seed or recovery phrase?  
> **username_0**: I would really appreciate if you could also mention the difference between them in your answer. I want to give my users master seeds for their wallets so that in future if they lose their wallets they can recover using the master seed they possess.  
> **username_1**: Give them the mnemonics. That's enough. They can recover their funds in any standard wallet if they have the mnemonics that represent the correct private keys of their wallet.  

---

## 1 answers

### Answer by username_1 on 2018-07-16. Score: 1 | Accepted answer

In case you are talking about mnemonic seed use this -

Install bitcore-mnemonic

```
npm install bitcore-mnemonic
bower install bitcore-mnemonic

```

Then use it to generate mnemonic seed -

```
var Mnemonic = require('bitcore-mnemonic');
var code = new Mnemonic(Mnemonic.Words.ENGLISH);
code.toString(); 
// army van defense carry jealous true garbage claim echo media make crunch...

var xpriv = code.toHDPrivateKey();

```

If you just want to generate a private from bitcore api you can use this function -

```
var bitcore = require('bitcore');
var HDPrivateKey = bitcore.HDPrivateKey;

```

Please note there is no rule to generate a private key. A private key is just a random string. It could even be your name or a whole article. But you must create a private key that is 'random' in nature. Also never use programming language functions like md5 hash or something to generate a private key because they are not truly random.

Bitcore api, however, provides an easy way to generate a private key using the above method. From there you can proceed as usual.

```
var bitcore = require('bitcore');
var HDPrivateKey = bitcore.HDPrivateKey;

var hdPrivateKey = new HDPrivateKey();
var retrieved = new HDPrivateKey('xpriv...');
var derived = hdPrivateKey.derive("m/0'");
var derivedByNumber = hdPrivateKey.derive(1).derive(2, true);
var derivedByArgument = hdPrivateKey.derive("m/1/2'");
assert(derivedByNumber.xprivkey === derivedByArgument.xprivkey);

var address = derived.privateKey.toAddress();

// obtain HDPublicKey
var hdPublicKey = hdPrivateKey.hdPublicKey;

```

> **Comments:**
> **username_0**: Hi username_1, thanks for your answer. Can you please also confirm if mnemonic seed is used at the time of recovering wallets when lost?  
> **username_1**: Yes, you can easily use mnemonics, in fact, in any standard wallet like trezor to recover back your funds. Mnemonics are actually created from private keys itself. You can learn about the process here - https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch05.asciidoc   When you use  var code = new Mnemonic(Mnemonic.Words.ENGLISH); bitcore api selects the private key for you and generates the mnemonics from it doing all the hard work for you. So you can think these mnemonics represents your private keys and you can use them to recover your funds.  
> **username_1**: Glad to help you.  If my answer meets your requirement please mark it as the accepted answer. Thanks  
> **username_0**: Done! username_1, I have a quick question for you. Mnemonic Seed will be created after a new wallet is created. Is that right? And if so, does it mean the created mnemonic seed will represent this wallet? Or do I need to do something to link the seed with my wallet??  
> **username_0**: Because as per my research so far, mnemonic is generated from a random string. So I'm confused how it will represent my wallet.  
> **username_1**: See the xpriv variable in the above code. It holds a HD private key. From this private key create public keys and addresses. Use only these addresses to transfer funds. So you need to 1. Generate mneomincs 2. Get your private keys from it as shown above. Then once you have HD private keys, generate addresses and HD public keys using the functions scripted in the answer.  
> **username_1**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/80270/discussion-between-username_1-username_1-and-username_0).  

---

