<p>I would suggest using a library such as the <a href="https://github.com/bitcoinjs/bitcoinjs-lib" rel="nofollow noreferrer">bitcoinjs-lib</a> library.</p>

<p>Here's a very stripped down example usage:</p>

<pre><code>let bitcoin = require("bitcoinjs-lib");

function fromXpub(xpub, acctNumber, keyindex, callback){
    let address = bitcoin.HDNode.fromBase58(xpub).derivePath(acctNumber+"/"+keyindex).getAddress(); 
    callback(address);
}

let myxpub = "xpub6C6RXXtdbxSnfB78Y4WjJSjQuChKqHXh9JCZPeKtdGeWRiptL9oJePPtrYKPWaoem9W3Wvp8eEh8dFFuN7u4zT6x6A1H6D67bVVvufv3uJ1";

fromXpub(myxpub, 0, 0, function(cb){
    console.log(cb);
});
</code></pre>

<blockquote>
  <blockquote>
    <p>13eX3ohuXCa93YgLCkuQF6NmJk8vUwqa8p</p>
  </blockquote>
</blockquote>

CC BY-SA 4.0
2018-10-03T02:52:55.527Z
Sorry but it seems that your code does not work on my side... i tried to change it to

`let address = bitcoin.bip32.fromBase58(xpub).derivePath(acctNumber+"/"+keyindex).__Q.toString('hex');` but i cant find the getAddress method here...
rW3ZpUdwYducwSuD
CC BY-SA 4.0
2018-09-26T04:29:51.730Z
2018-09-26T04:29:51.730Z
m1xolyd1an
<p>I'm looking for a lightweight node package which can handle creating btc receiving addresses on the server using an extended public key (segwit).</p>

<p>Like this one: zpub6nYqvTejCbqMTRTGz9rHkJnrJKbLsx36LqLnUJChDdJ6a5NA7hBumEpn9HTSDgWpNTNCponkPCBL5VKeAaScVxbXa1H4RPmA4j19rzgJPRp </p>

<p>I tried using <a href="https://www.npmjs.com/package/bitcoin-receive-payments" rel="nofollow noreferrer">https://www.npmjs.com/package/bitcoin-receive-payments</a>
But I don't want an OpenExchangeRates account to use this.</p>

<p>There is this guide on PHP <a href="https://freedomnode.com/blog/58/generate-bitcoin-wallet-addresses-from-extended-public-key-with-php" rel="nofollow noreferrer">https://freedomnode.com/blog/58/generate-bitcoin-wallet-addresses-from-extended-public-key-with-php</a></p>

<p>But I can't find any equivalent for JS.</p>

<p>I would also be very thankful if there is any explaination for non Math people, as I am just looking to generate addresses on a server based off an extended address.</p>

<p>Someone knows?</p>

<javascript><website-integration><wallet-development>
A NodeJS implementation on creating addresses from a Bitcoin (zpub, xpub) address
rW3ZpUdwYducwSuD
# A NodeJS implementation on creating addresses from a Bitcoin (zpub, xpub) address

(Asked by: username_0 on 2018-09-23)

I'm looking for a lightweight node package which can handle creating btc receiving addresses on the server using an extended public key (segwit).

Like this one: zpub6nYqvTejCbqMTRTGz9rHkJnrJKbLsx36LqLnUJChDdJ6a5NA7hBumEpn9HTSDgWpNTNCponkPCBL5VKeAaScVxbXa1H4RPmA4j19rzgJPRp

I tried using <https://www.npmjs.com/package/bitcoin-receive-payments>
But I don't want an OpenExchangeRates account to use this.

There is this guide on PHP <https://freedomnode.com/blog/58/generate-bitcoin-wallet-addresses-from-extended-public-key-with-php>

But I can't find any equivalent for JS.

I would also be very thankful if there is any explaination for non Math people, as I am just looking to generate addresses on a server based off an extended address.

Someone knows?

**Tags:** javascript, website-integration, wallet-development


---

## 1 answers

### Answer by username_1 on 2018-09-26. Score: 1

I would suggest using a library such as the [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib) library.

Here's a very stripped down example usage:

```
let bitcoin = require("bitcoinjs-lib");

function fromXpub(xpub, acctNumber, keyindex, callback){
    let address = bitcoin.HDNode.fromBase58(xpub).derivePath(acctNumber+"/"+keyindex).getAddress(); 
    callback(address);
}

let myxpub = "xpub6C6RXXtdbxSnfB78Y4WjJSjQuChKqHXh9JCZPeKtdGeWRiptL9oJePPtrYKPWaoem9W3Wvp8eEh8dFFuN7u4zT6x6A1H6D67bVVvufv3uJ1";

fromXpub(myxpub, 0, 0, function(cb){
    console.log(cb);
});

```

> > 13eX3ohuXCa93YgLCkuQF6NmJk8vUwqa8p

> **Comments:**
> **username_0**: Sorry but it seems that your code does not work on my side... i tried to change it to  `let address = bitcoin.bip32.fromBase58(xpub).derivePath(acctNumber+"/"+keyindex).__Q.toString('hex');` but i cant find the getAddress method here...  

---

