bitcoinjs / bitcoinjs-lib

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

Decode raw transaction addresses #1226

Closed brightsider closed 5 years ago

brightsider commented 5 years ago

How to decode input and output addresses in all available formats?

dcousens commented 5 years ago

@brightsider you're asking for us to write code for you.

But have you even tried anything?

Have you looked at any of the examples?

What does decode mean to you?

There is no such thing as an input address.

junderw commented 5 years ago

How to decode input and output addresses in all available formats?

The payments API is a good place to start looking.

https://github.com/bitcoinjs/bitcoinjs-lib/tree/master/src/payments

Happy Hunting!

brightsider commented 5 years ago

@dcousens I'm decoding addresses for outputs with this:

address = bitcoinjs.address.fromOutputScript(out.script, network)

for inputs:

let p2sh = bitcoinjs.payments.p2sh({
                            witness: input.witness,
                            network: network,
                            input: input.script
                        })
let address = p2sh.address

But sometimes get errors for both options. Input:

Output:

Examples of raw transactions with this errors:

0200000001a40c436b798305a45d21cb56111d78475b33e0554c140b734fbc7df6e94ae386010000006b483045022100e9c0a43bc187068c2452a7816491bad02c37835217cd5ff996e3941f7b1e9f00022055206e308d36f7cc779470c319b7314a024e5118baa3014813bd46df6b8214d90121021bd9fb009e3b8d1575d46503e1a0e688f3e27252f3a1b665b277cd7a093386acffffffff03102700000000000017a914ffd9114203951f645dbf58354ceddcb1737d8ea087b0690e01000000001976a914ea2b2473ec48af17e0913a6f367100cfeb39be6888ac0000000000000000116a0f62747400536167697474617269757300000000

01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff18039194150028000000677569646f20776173206865726500ffffffff017d161605000000001976a9142b2399d24a9e9e35487d2f76b57d6e33e72d522f88ac00000000

Can you help me with decoding this addresses?

junderw commented 5 years ago
  1. Coinbase transactions have no inputs.
  2. Not all inputs and outputs translate into an address.
  3. Learn about what an OP_RETURN output is.
brightsider commented 5 years ago

@junderw thanks