<p>First, note that <code>HDNode</code> was removed in <a href="https://github.com/bitcoinjs/bitcoinjs-lib/blob/96240b636d99fb0553aa7fc7722a13942bff1c83/CHANGELOG.md#400" rel="nofollow noreferrer">4.0.0</a>, so you should use the <code>BIP32</code> module you included. Second, you don't need the extra <code>keyPair</code> property, so your code becomes:</p>

<pre><code>var bip32 = require('bip32')

var privKey = process.env.BIP32_PRIV;
var hdNode = bip32.fromBase58(privKey);

var count = process.env.GENERATE_ADDRESSES ? parseInt(process.env.GENERATE_ADDRESSES) : 1000; // how many addresses to watch


var rescan = 'false';

for (var i = 1; i &lt;= count; ++i) {
  console.log('bitcoin-cli importprivkey ' +  hdNode.derive(i).toWIF() + " '' " + rescan)
}
</code></pre>

CC BY-SA 4.0
2019-01-27T06:12:46.343Z
2019-01-27T06:12:46.343Z
JBaczuk
<p>I am working on a cryptocurrency site in which each user will have there own individual deposit address to put currency on site. I am using bitcoin-core, bitcoinjs-lib, along with quite a few other modules.</p>

<p>Currently I am receiving an error after running the following code via <code>node generate_wallet.js</code></p>

<pre><code>var bip32 = require('bip32')
var bitcoinjs = require('bitcoinjs-lib');

var privKey = process.env.BIP32_PRIV;
var hdNode = bitcoinjs.HDNode.fromBase58(privKey);

var count = process.env.GENERATE_ADDRESSES ? parseInt(process.env.GENERATE_ADDRESSES) : 1000; // how many addresses to watch


var rescan = 'false';

for (var i = 1; i &lt;= count; ++i) {
  console.log('bitcoin-cli importprivkey ' +  hdNode.derive(i).keyPair.toWIF() + " '' " + rescan)
}
</code></pre>

<p>The error:</p>

<pre><code>console.log('bitcoin-cli importprivkey ' +  hdNode.derive(i).keyPair.toWIF(L4tvCJoE9nxFnmZ4znCDvpqMLo9m8ybpAzxdE4ZKWDAfBqeM8JsR) + " '' " + rescan)
                                                                      ^

TypeError: Cannot read property 'toWIF' of undefined
    at Object.&lt;anonymous&gt; (/root/bustabit-depositor/src/generate_wallet.js:13:71)
    at Module._compile (internal/modules/cjs/loader.js:736:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
    at Function.Module._load (internal/modules/cjs/loader.js:560:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
    at executeUserCode (internal/bootstrap/node.js:526:15)
    at startMainThreadExecution (internal/bootstrap/node.js:439:3)
root@ubuntu:~/bustabit-depositor/src#
</code></pre>

<p>Any suggestions would be greatly appreciated. I don't even know how to work around this as there's no results online about this. Maybe i'm just dumb haha</p>

<bitcoin-core><bip32-hd-wallets><bitcoinjs>
Cannot read property 'toWIF' of undefined
Mason
# Cannot read property 'toWIF' of undefined

(Asked by: username_0 on 2019-01-27)

I am working on a cryptocurrency site in which each user will have there own individual deposit address to put currency on site. I am using bitcoin-core, bitcoinjs-lib, along with quite a few other modules.

Currently I am receiving an error after running the following code via `node generate_wallet.js`

```
var bip32 = require('bip32')
var bitcoinjs = require('bitcoinjs-lib');

var privKey = process.env.BIP32_PRIV;
var hdNode = bitcoinjs.HDNode.fromBase58(privKey);

var count = process.env.GENERATE_ADDRESSES ? parseInt(process.env.GENERATE_ADDRESSES) : 1000; // how many addresses to watch

var rescan = 'false';

for (var i = 1; i <= count; ++i) {
  console.log('bitcoin-cli importprivkey ' +  hdNode.derive(i).keyPair.toWIF() + " '' " + rescan)
}

```

The error:

```
console.log('bitcoin-cli importprivkey ' +  hdNode.derive(i).keyPair.toWIF(L4tvCJoE9nxFnmZ4znCDvpqMLo9m8ybpAzxdE4ZKWDAfBqeM8JsR) + " '' " + rescan)
                                                                      ^

TypeError: Cannot read property 'toWIF' of undefined
    at Object.<anonymous> (/root/bustabit-depositor/src/generate_wallet.js:13:71)
    at Module._compile (internal/modules/cjs/loader.js:736:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
    at Function.Module._load (internal/modules/cjs/loader.js:560:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
    at executeUserCode (internal/bootstrap/node.js:526:15)
    at startMainThreadExecution (internal/bootstrap/node.js:439:3)
root@ubuntu:~/bustabit-depositor/src#

```

Any suggestions would be greatly appreciated. I don't even know how to work around this as there's no results online about this. Maybe i'm just dumb haha

**Tags:** bitcoin-core, bip32-hd-wallets, bitcoinjs


---

## 1 answers

### Answer by username_1 on 2019-01-27. Score: 1

First, note that `HDNode` was removed in [4.0.0](https://github.com/bitcoinjs/bitcoinjs-lib/blob/96240b636d99fb0553aa7fc7722a13942bff1c83/CHANGELOG.md#400), so you should use the `BIP32` module you included. Second, you don't need the extra `keyPair` property, so your code becomes:

```
var bip32 = require('bip32')

var privKey = process.env.BIP32_PRIV;
var hdNode = bip32.fromBase58(privKey);

var count = process.env.GENERATE_ADDRESSES ? parseInt(process.env.GENERATE_ADDRESSES) : 1000; // how many addresses to watch

var rescan = 'false';

for (var i = 1; i <= count; ++i) {
  console.log('bitcoin-cli importprivkey ' +  hdNode.derive(i).toWIF() + " '' " + rescan)
}

```


---

