bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.65k stars 2.09k forks source link

Can't resolve all parameters for ECPair: (?, ?, ?) #946

Closed chiemekailo closed 6 years ago

chiemekailo commented 6 years ago

I am new to Ionic/Angular programming and designs (used to design iOS apps). I have the following problem with the bitcoinjs-lib:

I try to implement bitcoinjs-lib in a new angular 4.x app. What i did :

npm install bitcoinjs-lib --save
npm install @types/bitcoinjs-lib --save

My app.module.ts :

import { ECPair, HDNode, Transaction } from 'bitcoinjs-lib'

@NgModule({
  ...
  providers: [
    ...
    ECPair,
    HDNode,
    Transaction
  ]
})

It fails to Compile in my browser :

Uncaught Error: Can't resolve all parameters for ECPair: (?, ?, ?).
    at syntaxError (compiler.js:466)

This question has been asked on https://stackoverflow.com/questions/47231555/cant-resolve-all-parameters-for-ecpair, but the selected correct answer which was...

You have to provide it properly. In your @NgModule you should use something like this:

@NgModule({
...
providers: [
...
{ ECPair, useFactory:()=>new ECPair(d,Q,options) }
]
})

Specify appropriate arguments for d Q and options.

...didn't teach on how to appropriately specify the 'd', 'Q' and 'options' arguments for the app.module.ts file. Please, what do I do?

dcousens commented 6 years ago

I don't know Angular/Ionic, so I can't help you here. Maybe someone else is around who could help?

dcousens commented 6 years ago

@chiemekailo if you can resolve this, please reply back for others. But I don't think this is an issue related to bitcoinjs-lib specifically.

sushrest commented 6 years ago

Hi @chiemekailo, This may be very old issue for you.. if could recall could u pls share how you got around fixing this issue?

chiemekailo commented 5 years ago

@chiemekailo if you can resolve this, please reply back for others. But I don't think this is an issue related to bitcoinjs-lib specifically.

Hi @chiemekailo, This may be very old issue for you.. if could recall could u pls share how you got around fixing this issue?

Hi. I only recently approached the issue again, and here’s my original mistake. I was trying to use the library on the client application, instead of on a server. @dcousens was right, it was not intended for the ionic-type implementation. So it is all up and running now on my NodeJS server. Thanks. Pretty straightforward too.