<p>According to BIP32 you're trying to generate a non-hardened child address, see <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#public-parent-key--public-child-key" rel="nofollow noreferrer">BIP32 - Public parent key → public child key</a>.</p>

<p>Using bitcore-lib, to derive a non-hardened child public key and a P2PKH address:</p>

<pre><code>var bitcore = require('bitcore-lib');
var Address = bitcore.Address;
var PublicKey = bitcore.PublicKey;
var Networks = bitcore.Networks;

var hdPublickey = new bitcore.HDPublicKey('tpubD6NzVbkrYhZ4XLMmry7XriYJ6Xgx1vQqoUZHLUXQPDB32n7pQYaWSMpRttm2sHzYjsQqrsAZYyJCmoEJB51oSdqZxq7epGjP4vHriCYz7Tp');
var orderPublickey = hdPublickey.deriveChild("m/44/145/0/0");
var pubkey = new PublicKey(orderPublickey.publicKey);
var address = Address.fromPublicKey(pubkey, Networks.testnet);
console.log("address", address);
</code></pre>

<p>Returns:<br>
<code>address &lt;Address: mkVBk6gZ7rBLYXvpdcKwTEq6SjHvSeLwZ8, type: pubkeyhash, network: testnet&gt;</code></p>

CC BY-SA 4.0
2018-07-24T13:51:54.457Z
could we convert  this publicKey into bitcoin base58 address?
rahul_eth
CC BY-SA 4.0
2018-07-24T13:58:22.923Z
I got this method bitcore.Address.fromPublicKey() but it is not working
rahul_eth
CC BY-SA 4.0
2018-07-24T14:02:49.980Z
What is it doing? Also, try `var address = Address(publicKey, 'mainnet').toString();` Also it depends on what type of address you want (`p2sh` or `p2pkh`)
JBaczuk
CC BY-SA 4.0
2018-07-24T14:05:29.680Z
please define Address? do you have any working code that can generate bitcoin address from xpub?
rahul_eth
CC BY-SA 4.0
2018-07-24T14:14:38.417Z
Have you tried the above? Is it not working for you?
JBaczuk
CC BY-SA 4.0
2018-07-24T14:20:58.230Z
i have tried lots of time in addr = Address(publicKey, 'mainnet').toString(), i am trying to figure out how to define Address??
rahul_eth
CC BY-SA 4.0
2018-07-24T14:32:31.960Z
see my edit above.
JBaczuk
CC BY-SA 4.0
2018-07-24T14:49:45.107Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/80609/discussion-between-jbaczuk-and-rahul-saini).
JBaczuk
CC BY-SA 4.0
2018-07-25T06:15:35.503Z
hii @JBaczuk i inboxed you
rahul_eth
CC BY-SA 4.0
2019-11-18T14:18:35.307Z
How can i get the privatekey for the above adddress mkVBk6gZ7rBLYXvpdcKwTEq6SjHvSeLwZ8
Ishwar Chandra Tiwari
CC BY-SA 4.0
2019-11-18T15:59:02.710Z
@IshwarChandra you can't. If you could, then how would you ever hold Bitcoin without someone computing your private key and stealing your funds?
JBaczuk
CC BY-SA 4.0
2019-11-18T16:29:07.740Z
@JBaczuk yeah i know .you are right.....
Ishwar Chandra Tiwari
CC BY-SA 4.0
2019-11-18T16:35:36.640Z
@JBaczuk today i exported xpub from coinomi and used in the above code to generate bitcoin address and sent bitcoin.... now my problem is how can i get the fund i sent to that new bitcoin address, which is not in my coinomi wallet and even i did not get any notification incoming transaction on my coinomi wallet
Ishwar Chandra Tiwari
CC BY-SA 4.0
2019-11-18T17:16:07.400Z
@IshwarChandra doing that is most likely is not supported by their application. Hopefully you can export your private key from coinomi, then you'll have to figure out how to sign a transaction with that key and send it back to an address in one of your wallet applications.
JBaczuk
CC BY-SA 4.0
2019-11-18T18:55:59.403Z
@JBaczuk thanks, my requirement is if someone sharing me his xpub from exodus or any xpub supported wallet and i am creating bitcoin address using that xpub so is there any way like he can manage those funds. I mean, I will only generate the addresses using xpub and the one who is having xpub, xpriv and its mnemonic he can access/use that funds.
Ishwar Chandra Tiwari
CC BY-SA 4.0
2019-11-18T18:57:52.060Z
@IshwarChandra There are ways, but I don't know if there are any wallets that would support what you want out of the box. You might have to create your own.
JBaczuk
CC BY-SA 4.0
2018-07-24T13:40:25.443Z
2018-07-25T15:15:35.573Z
2018-07-25T15:15:35.573Z
JBaczuk
<p>I want to create bitcoin address from extended public key, without exposing private key but did not get any success till now. Do someone know how to do it? I am using bitcore-lib package</p>

CC BY-SA 4.0
2018-07-24T13:36:49.713Z
can you provide any code and the problems you're having?
JBaczuk
<public-key><address-generation><bitcore>
bitcoin address from xpub key
rahul_eth
# bitcoin address from xpub key

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

I want to create bitcoin address from extended public key, without exposing private key but did not get any success till now. Do someone know how to do it? I am using bitcore-lib package

**Tags:** public-key, address-generation, bitcore

> **Comments:**
> **username_1**: can you provide any code and the problems you're having?  

---

## 1 answers

### Answer by username_1 on 2018-07-24. Score: 2

According to BIP32 you're trying to generate a non-hardened child address, see [BIP32 - Public parent key → public child key](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#public-parent-key--public-child-key).

Using bitcore-lib, to derive a non-hardened child public key and a P2PKH address:

```
var bitcore = require('bitcore-lib');
var Address = bitcore.Address;
var PublicKey = bitcore.PublicKey;
var Networks = bitcore.Networks;

var hdPublickey = new bitcore.HDPublicKey('tpubD6NzVbkrYhZ4XLMmry7XriYJ6Xgx1vQqoUZHLUXQPDB32n7pQYaWSMpRttm2sHzYjsQqrsAZYyJCmoEJB51oSdqZxq7epGjP4vHriCYz7Tp');
var orderPublickey = hdPublickey.deriveChild("m/44/145/0/0");
var pubkey = new PublicKey(orderPublickey.publicKey);
var address = Address.fromPublicKey(pubkey, Networks.testnet);
console.log("address", address);

```

Returns:  
`address <Address: mkVBk6gZ7rBLYXvpdcKwTEq6SjHvSeLwZ8, type: pubkeyhash, network: testnet>`

> **Comments:**
> **username_0**: could we convert  this publicKey into bitcoin base58 address?  
> **username_0**: I got this method bitcore.Address.fromPublicKey() but it is not working  
> **username_1**: What is it doing? Also, try `var address = Address(publicKey, 'mainnet').toString();` Also it depends on what type of address you want (`p2sh` or `p2pkh`)  
> **username_0**: please define Address? do you have any working code that can generate bitcoin address from xpub?  
> **username_1**: Have you tried the above? Is it not working for you?  
> **username_0**: i have tried lots of time in addr = Address(publicKey, 'mainnet').toString(), i am trying to figure out how to define Address??  
> **username_1**: see my edit above.  
> **username_1**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/80609/discussion-between-username_1-and-rahul-saini).  
> **username_0**: hii @username_1 i inboxed you  
> **username_2**: How can i get the privatekey for the above adddress mkVBk6gZ7rBLYXvpdcKwTEq6SjHvSeLwZ8  
> **username_1**: @IshwarChandra you can't. If you could, then how would you ever hold Bitcoin without someone computing your private key and stealing your funds?  
> **username_2**: @username_1 yeah i know .you are right.....  
> **username_2**: @username_1 today i exported xpub from coinomi and used in the above code to generate bitcoin address and sent bitcoin.... now my problem is how can i get the fund i sent to that new bitcoin address, which is not in my coinomi wallet and even i did not get any notification incoming transaction on my coinomi wallet  
> **username_1**: @IshwarChandra doing that is most likely is not supported by their application. Hopefully you can export your private key from coinomi, then you'll have to figure out how to sign a transaction with that key and send it back to an address in one of your wallet applications.  
> **username_2**: @username_1 thanks, my requirement is if someone sharing me his xpub from exodus or any xpub supported wallet and i am creating bitcoin address using that xpub so is there any way like he can manage those funds. I mean, I will only generate the addresses using xpub and the one who is having xpub, xpriv and its mnemonic he can access/use that funds.  
> **username_1**: @IshwarChandra There are ways, but I don't know if there are any wallets that would support what you want out of the box. You might have to create your own.  

---

