bitcoinjs / bitcoinjs-lib

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

`TypeError: Cannot read property 'output' of undefined #1164

Closed bellaj closed 5 years ago

bellaj commented 5 years ago

I've installed the latest version but When i use

var bitcoin = require('bitcoinjs-lib')
const prevOutScript = bitcoin.script.scriptHash.output.encode(..)

i get TypeError: Cannot read property 'output' of undefined

dabura667 commented 5 years ago

Try this:

https://github.com/bitcoinjs/bitcoinjs-lib/blob/718c52f852d78453800b7618454f932c164fcfc5/test/integration/transactions.js#L105-L141

dcousens commented 5 years ago

Specifically

bitcoin.payments.p2sh({ hash })

In your case. Assuming I understood what you are trying to do.

bellaj commented 5 years ago

Thanks for your answers. I am trying to construct a raw transaction by consuming a P2SH input . I've found an example in transaction.js but it's using a segwit p2wpkh redeem script which I am trying to avoid because many broadcasting APIs (blockcypher...) don't support segwit yet. So can i construct a raw transactions without segwit redeem script?

junderw commented 5 years ago

@bellaj the example given by @dabura667 is not segwit.........

https://github.com/bitcoinjs/bitcoinjs-lib/blob/718c52f852d78453800b7618454f932c164fcfc5/test/integration/transactions.js#L105-L141

junderw commented 5 years ago

what kind of p2sh are you trying to use? your original question was attempting to make a p2sh output... what kind of p2sh output are you trying to consume?

We need more information to help you. Please give us an address, a redeemscript, anything to help us help you.

dcousens commented 5 years ago

@bellaj if you have another question, please open another appropriately titled issue :)