<p>You seem to be using an old version of bitcoinjs-lib. The <code>payments</code> interface was added in version <a href="https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/CHANGELOG.md#400" rel="nofollow noreferrer">4.0.0</a> which was released in 2018.</p>
<p>Note that the <code>ECPair</code> interface was removed in <a href="https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/CHANGELOG.md#600" rel="nofollow noreferrer">6.0.0</a> so this code won't work on the latest version either. <code>bip32</code> should be used instead.</p>

CC BY-SA 4.0
2023-03-25T20:04:15.653Z
2023-03-25T20:04:15.653Z
Vojtěch Strnad
<p>I've installed the latest version of bitcoinjs-lib but I cannot use the functions of the library.</p>
<pre class="lang-js prettyprint-override"><code>const bitcoin = require('bitcoinjs-lib');
const keyPair = bitcoin.ECPair.makeRandom();
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
</code></pre>
<p>I get errors like:</p>
<pre><code>TypeError: Cannot read properties of undefined (reading 'p2pkh')
</code></pre>
<p>Can you help?</p>

CC BY-SA 4.0
2024-01-07T14:49:05.847Z
I’m voting to close this question because it's a general programming question not specific to Bitcoin.
Antoine Poinsot
<javascript><bitcoinjs>
bitcoinjs-lib is installed but cannot use its functions
Tornike Tskhvediani
# bitcoinjs-lib is installed but cannot use its functions

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

I've installed the latest version of bitcoinjs-lib but I cannot use the functions of the library.
const bitcoin = require('bitcoinjs-lib');
const keyPair = bitcoin.ECPair.makeRandom();
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });

I get errors like:
TypeError: Cannot read properties of undefined (reading 'p2pkh')

Can you help?

**Tags:** javascript, bitcoinjs

> **Comments:**
> **username_1**: I’m voting to close this question because it's a general programming question not specific to Bitcoin.  

---

## 1 answers

### Answer by username_2 on 2023-03-25. Score: 2

You seem to be using an old version of bitcoinjs-lib. The `payments` interface was added in version [4.0.0](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/CHANGELOG.md#400) which was released in 2018.

Note that the `ECPair` interface was removed in [6.0.0](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/CHANGELOG.md#600) so this code won't work on the latest version either. `bip32` should be used instead.


---

