Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECPairFactory is not a function #3

Closed
Alf71 opened this issue Mar 30, 2022 · 9 comments
Closed

ECPairFactory is not a function #3

Alf71 opened this issue Mar 30, 2022 · 9 comments

Comments

@Alf71
Copy link

Alf71 commented Mar 30, 2022

TypeError: require(...).ECPairFactory is not a function

@antonilol
Copy link
Owner

Did you npm install?

@Alf71
Copy link
Author

Alf71 commented Mar 30, 2022

Yes, both:

npm install bitcoinjs-lib
npm install ecpair

@antonilol
Copy link
Owner

Which script did you try to run?
Which OS do you have and which node and npm version do you run?

What does require('ecpair') print in nodejs repl?

@Alf71
Copy link
Author

Alf71 commented Mar 30, 2022

Ubuntu Server 18 running in Win10
priv_key_recovery.js
Node.js v14.16.1

`
node priv_key_recovery.js
/home/admin/recover/priv_key_recovery.js:2
const ECPair = require('ecpair').ECPairFactory(require('tiny-secp256k1'));
^

TypeError: require(...).ECPairFactory is not a function
at Object. (/home/admin/recover/priv_key_recovery.js:2:34)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47`

@antonilol
Copy link
Owner

i cant reproduce this (archlinux)
i tried the exact nodejs version (v14.16.1)

what does node -pe "require('ecpair')" print?
i get { default: [Getter], ECPairFactory: [Getter], networks: [Getter] } (it should include the ECPairFactory)

what version op ecpair do you have installed?
i have 2.0.1:

$ cat node_modules/ecpair/package.json | grep version
  "version": "2.0.1",

@Alf71
Copy link
Author

Alf71 commented Mar 30, 2022

I'm getting

{
networks: {
bitcoin: {
messagePrefix: '\x18Bitcoin Signed Message:\n',
bech32: 'bc',
bip32: [Object],
pubKeyHash: 0,
scriptHash: 5,
wif: 128
},
testnet: {
messagePrefix: '\x18Bitcoin Signed Message:\n',
bech32: 'tb',
bip32: [Object],
pubKeyHash: 111,
scriptHash: 196,
wif: 239
}
},
ECPair: [class ECPair]
}

@Alf71
Copy link
Author

Alf71 commented Mar 30, 2022

cat node_modules/ecpair/package.json | grep version
cat: node_modules/ecpair/package.json: No such file or directory

@antonilol
Copy link
Owner

looks like a really old version of bitcoinjs lib and ecpair
i think this patch will fix it but consider updating your node/npm

diff --git a/priv_key_recovery.js b/priv_key_recovery.js
index 35fd65d..40b68db 100644
--- a/priv_key_recovery.js
+++ b/priv_key_recovery.js
@@ -1,5 +1,5 @@
 const bitcoin = require('bitcoinjs-lib');
-const ECPair = require('ecpair').ECPairFactory(require('tiny-secp256k1'));
+const { ECPair } = require('ecpair');
 
 const base58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'.split('');

@Alf71
Copy link
Author

Alf71 commented Mar 30, 2022

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants