Author

Topic: Transaction inputs and outputs with multiple addresses (Read 230 times)

legendary
Activity: 4466
Merit: 3391
As @pooya87 explained, an output doesn't have an address. It has a script. There are scripts with no addresses (for example, a pay-to-any transaction), and there can be scripts with multiple addresses. It is all up to the script contained in the output.

The most common type of Bitcoin transaction is called pay-to-pubkey-hash (P2PKH), which is a transaction that sends bitcoins to an address. The script contains an address (in the form of a "pubkey hash") and a block explorer extracts it from the script and displays it as the destination address.

legendary
Activity: 3472
Merit: 10611
unless it was some weird custom script.

^^ this
and it probably is due to lazy developers copying code because it doesn't work where it should. i found a better example: https://api.blockcypher.com/v1/btc/test3/txs/8d897ca91774a7fafa086a3275e679248d6bffee015d3b2efefd5dab00df152d?limit=50&includeHex=true
as you can see at the bottom of the page it says ""addresses": null," for the following output:
Code:
76a9145f1426c2ce4a8e1abaa9dbe819b6303eb8a25a2688ad6376a9146c7ceafe76c56843c9d2868f616fdc9370355eb988ac67aa20644d79d87e0907833e888e272e5d7b925deb261a8499a65cbc0bf26797a15e8e8768
which is
Code:
76 a9 14 5f1426c2ce4a8e1abaa9dbe819b6303eb8a25a26 88 ad


63

76 a9 14 6c7ceafe76c56843c9d2868f616fdc9370355eb9 88 ac


67


aa 20 644d79d87e0907833e888e272e5d7b925deb261a8499a65cbc0bf26797a15e8e 87


68


so it has 2 addresses with P2PKH scripts (so 2 base58 encoding here which will result in addresses starting with 1 or in case of testnet with m) and a third double SHA256 result which i can't tell what it is, it can be result of hash of a public key or anything else!
HCP
legendary
Activity: 2086
Merit: 4361
these arrays have nothing to do with input/output, these arrays are simply telling you the addresses that were involved in the transaction.
...snip...
to keep the code consistent, everywhere else that lists addresses like this (like txinput) will also use a string array as its type.
Yes, but you're looking at the TX level... OP was talking specifically about the TXOutput level.

As you have said, at the TXInput and TXOutput level they are still arrays... and indeed, if you look further down in your example tx decode,  you'll see the "addresses" arrays listed under each "inputs" and "outputs". Even though they only contain a single address, they're still in array notation with the square brackets ie. [ "..." ]

Theoretically, they could show multiple addresses as they are arrays and while that would be valid from a purely syntactical point of view, in practice, I don't think that this would actually decode to a "valid" transaction unless it was some weird custom script.

I concur that it was likely just a design decision made in the early days and has never been corrected for one reason or another.
legendary
Activity: 3472
Merit: 10611
~ I wanted to confirm if there is / can be a case where I will face an output with more than one address.

outputs are not addresses, they are scripts. some of them (which would shape up majority of transactions) can be converted to addresses.
knowing that, you have to "read" the script and in that it is possible to see anything including more than one address. here is an example transaction:
055f9c6dc094cf21fa224e1eb4a54ee3cc44ae9daa8aa47f98df5c73c48997f9
if you decode it, the pubkey script of it is this:
5121030e001332b43924be343986cca3df669f57b0dedd120990e727787f8dea50fdbc211000000 0000000000000000000000000000000000000000000000000000000000052ae

so there is technically two addresses here:
030e001332b43924be343986cca3df669f57b0dedd120990e727787f8dea50fdbc
and
100000000000000000000000000000000000000000000000000000000000000000 (although this is an invalid pubkey in this particular case but it didn't need to be)

a better example would have been using OP_IF and things like that but i couldn't find any actual one.
newbie
Activity: 35
Merit: 0
A partial answer is probably in the same API docs for the TXoutput:

Quote
addresses   array[string]

Addresses that correspond to this output; typically this will only have a single address, and you can think of this output as having “sent” value to the address contained herein

I'm not aware of any current use cases that have multiple addresses for a single output... perhaps it was going to be a planned feature that was simply never implemented... but the API was left as is. Huh

Also, you should note that this is the Blockcypher API, which is not necessarily identical to the Bitcoin spec...

I am using this tool https://github.com/libbitcoin/libbitcoin-system/blob/79442071497efe14801d103dd5d400dc3157bbf6/include/bitcoin/system/chain/output.hpp and I face the same issue, I wanted to confirm if there is / can be a case where I will face an output with more than one address.

legendary
Activity: 3472
Merit: 10611
these arrays have nothing to do with input/output, these arrays are simply telling you the addresses that were involved in the transaction.
for example if you look at the Tx example (https://api.blockcypher.com/v1/btc/main/txs/f854aebae95150b379cc1187d848d58225f3c4157fe992bcd166f58bd5063449) you can see there is an array of addresses like this:
"addresses": [
    "13XXaBufpMvqRqLkyDty1AXqueZHVe6iyy",
    "19YtzZdcfs1V2ZCgyRWo8i2wLT8ND1Tu4L",
    "1BNiazBzCxJacAKo2yL83Wq1VJ18AYzNHy",
    "1GbMfYui17L5m6sAy3L3WXAtf1P32bxJXq",
    "1N2f642sbgCMbNtXFajz9XDACDFnFzdXzV"
],
the first 4 addresses are the ones that are spending their own outputs (4 tx_in from 4 addresses) and the last one is the one they are paying to (1 tx_out to one address).
this is just a quick way of figuring out what addresses were involved in this particular transaction (f854aeb....)
to keep the code consistent, everywhere else that lists addresses like this (like txinput) will also use a string array as its type.
HCP
legendary
Activity: 2086
Merit: 4361
A partial answer is probably in the same API docs for the TXoutput:

Quote
addresses   array[string]

Addresses that correspond to this output; typically this will only have a single address, and you can think of this output as having “sent” value to the address contained herein

I'm not aware of any current use cases that have multiple addresses for a single output... perhaps it was going to be a planned feature that was simply never implemented... but the API was left as is. Huh

Also, you should note that this is the Blockcypher API, which is not necessarily identical to the Bitcoin spec...
newbie
Activity: 35
Merit: 0
I understand that bitcoin transaction has 1 or more inputs and 1 or more outputs.

I was assuming, that each input and output is related to a single address, however, when reading the blockcypher api docs I read:
Quote
addresses array[string]

An array of public addresses associated with the output of the previous transaction.


How is it possible that multiple addresses are involved with a single input or output? I was thinking of multi-signature transactions, however, afaik this would be accomplished by writing a script, which would then be hashed (or double-hashed, since btc folks like to double-hash all the things Smiley) which would represent the P2SH address, right?



Disclaimer:

I searched the internet with no success, all I was able to find were questions à la "Why does a BTC tx have multiple inputs/outputs". Also, I'm not a native English speaker, so forgive me any probably existing mistakes I made.
Jump to: