bitcoinjs / bitcoinjs-lib

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

No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance #1889

Closed MadhuraJoshi1 closed 1 year ago

MadhuraJoshi1 commented 1 year ago

I am able to get transaction hex to send bitcoins from native segwit address to legacy , nested segwit and native segwit address but when i try to send bitcoin from native segwit to taproot address I am not able to add the outputs.

Here I am trying to add output for taproot address but it throws " No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance " error .

psbt.addOutput({ address: tb1p......., value: amount });

junderw commented 1 year ago

As you can see here: https://github.com/bitcoinjs/bitcoinjs-lib/blob/v6.1.0/test/integration/taproot.spec.ts#L3-L15

You need to import an ecc library that is compatible with bitcoinjs-lib, and call initEccLib (which is at the root of this library) to load in an ecc library to calculate the address correctly.

If you can't use WASM in your project, then other people have suggested alternative implementations. https://github.com/bitcoinjs/bitcoinjs-lib/issues/1781#issuecomment-1302025310