<p>Recently, I wrote a c++ code to extract some information from some messages in BITCOIN protocol. for example, I extracted bitcoin value and output address corresponded to it from tx messages of this protocol.</p>

<p>Extraction algorithm for output addresses is based on type of scripts such as P2PK, P2PKH, P2SH, P2WPKH and etc. but it is not clear how to extract input addresses.</p>

<p>can anyone explain what is the extraction method for input addresses in tx messages?</p>

CC BY-SA 4.0
2019-06-15T06:07:51.430Z
Inputs don't have addresses. Outputs do. Inputs spend previous outputs. You'll need to find the output being spent to figure out the address (which is not explicit in the protocol), but generally this is not interesting information for anything but debug purposes.
Pieter Wuille
CC BY-SA 4.0
2019-06-15T06:50:00.303Z
@PieterWuille You mean that every address which is shown in bitcoin explorers are previous outputs?  I know that UTXO's are same previous outputs, but what about other transactions?
Saeed
CC BY-SA 4.0
2019-06-15T06:52:09.033Z
Yes, that's exactly what UTXO means: unspent transaction *output*. An input simply spends a UTXO and gets to create new ones with the redeemed value. Bitcoin transaction inputs do not contains addresses or amounts; simply the identifier of a UTXO being spent, and the signature data necessary to authorize the spend.
Pieter Wuille
CC BY-SA 4.0
2019-06-15T07:33:35.603Z
@PieterWuille So how I can access the transactions which  their output addresses spent as input address for current transaction?
Saeed
CC BY-SA 4.0
2019-06-15T07:58:56.037Z
No, you must have seen them when they were broadcast or included in a block, and remember them. Note that in order to be able to spend them, you need this information anyway.
Pieter Wuille
CC BY-SA 4.0
2019-06-15T08:06:29.690Z
As a personal comment judging by the questions you're asking: trying to learn Bitcoin by trying to decipher pcap dumps is not going to teach you much. The Bitcoin protocol is  designed for interaction between Bitcoin nodes, which maintain state, and interact in various ways. Looking at the operation of those nodes directly will explain a lot more than trying to infer it from the trail of TCP messages you can observe.
Pieter Wuille
<transactions><bitcoin-core><address><script>
Extract input addresses from a tx message in bitcoin protocol
Saeed
# Extract input addresses from a tx message in bitcoin protocol

(Asked by: username_0 on 2019-06-15)

Recently, I wrote a c++ code to extract some information from some messages in BITCOIN protocol. for example, I extracted bitcoin value and output address corresponded to it from tx messages of this protocol.

Extraction algorithm for output addresses is based on type of scripts such as P2PK, P2PKH, P2SH, P2WPKH and etc. but it is not clear how to extract input addresses.

can anyone explain what is the extraction method for input addresses in tx messages?

**Tags:** transactions, bitcoin-core, address, script

> **Comments:**
> **username_1**: Inputs don't have addresses. Outputs do. Inputs spend previous outputs. You'll need to find the output being spent to figure out the address (which is not explicit in the protocol), but generally this is not interesting information for anything but debug purposes.  
> **username_0**: @username_1 You mean that every address which is shown in bitcoin explorers are previous outputs?  I know that UTXO's are same previous outputs, but what about other transactions?  
> **username_1**: Yes, that's exactly what UTXO means: unspent transaction *output*. An input simply spends a UTXO and gets to create new ones with the redeemed value. Bitcoin transaction inputs do not contains addresses or amounts; simply the identifier of a UTXO being spent, and the signature data necessary to authorize the spend.  
> **username_0**: @username_1 So how I can access the transactions which  their output addresses spent as input address for current transaction?  
> **username_1**: No, you must have seen them when they were broadcast or included in a block, and remember them. Note that in order to be able to spend them, you need this information anyway.  
> **username_1**: As a personal comment judging by the questions you're asking: trying to learn Bitcoin by trying to decipher pcap dumps is not going to teach you much. The Bitcoin protocol is  designed for interaction between Bitcoin nodes, which maintain state, and interact in various ways. Looking at the operation of those nodes directly will explain a lot more than trying to infer it from the trail of TCP messages you can observe.  

---

## 0 answers

