1

I'm using JSON-RPC call to connect to local bitcoin node on my clouding server.

I could get all transactions with wallet name by using gettransactions. Now I need to get sender's address for each transaction but result contains only receivers' address.

Following is response of gettransactions request.

{
    "result": [
        {
            "address": "bc1qd9mgd4ynryaw2kp0pzfjdxguhz9dzvs5vh0nfn",
            "category": "receive",
            "amount": 0.001,
            "label": "",
            "vout": 27,
            "confirmations": 1322,
            "blockhash": "000000000000000000074551080f954e790edfe6ad810ecebf4691e881175eaf",
            "blockheight": 660029,
            "blockindex": 106,
            "blocktime": 1607147554,
            "txid": "07ab59c8d3a204172887085258460d0058c20a9acdb451daa5ad4290cbd461b0",
            "walletconflicts": [],
            "time": 1607147511,
            "timereceived": 1607147511,
            "bip125-replaceable": "no"
        },
        {
            "address": "bc1q6dh3h5e3qgku8u9s8y664844fj4fkm08n7cnwt",
            "category": "receive",
            "amount": 0.0011,
            "label": "",
            "vout": 9,
            "confirmations": 1313,
            "blockhash": "00000000000000000000960f4476a8552cac203eec6e0f826886b41fae402bec",
            "blockheight": 660038,
            "blockindex": 393,
            "blocktime": 1607153799,
            "txid": "af0885e4c1d10e935de525680c6c33d221ab506742b08e34a0322bba90b56fb0",
            "walletconflicts": [],
            "time": 1607152236,
            "timereceived": 1607152236,
            "bip125-replaceable": "no"
        },
        {
            "address": "1L8ZNCibVVpPjJ8VJ1ALLuTjtctA4mzGPw",
            "category": "send",
            "amount": -0.001,
            "vout": 0,
            "fee": -0.00008536,
            "confirmations": 706,
            "blockhash": "0000000000000000000c3230522e267980bb990883cc0b36460ad3efc1f8fed4",
            "blockheight": 660645,
            "blockindex": 1049,
            "blocktime": 1607529332,
            "txid": "a2056e7a49bc608435713519bc038ed7da2e65f588495f36c6628f5ca6fe2d7d",
            "walletconflicts": [],
            "time": 1607528963,
            "timereceived": 1607528963,
            "bip125-replaceable": "no",
            "comment": " ",
            "to": "seans outpost",
            "abandoned": false
        },
        {
            "address": "1L8ZNCibVVpPjJ8VJ1ALLuTjtctA4mzGPw",
            "category": "send",
            "amount": -0.0005,
            "vout": 1,
            "fee": -0.00008536,
            "confirmations": 705,
            "blockhash": "0000000000000000000994e21412109847caffa2bd990884f49461d53c047055",
            "blockheight": 660646,
            "blockindex": 844,
            "blocktime": 1607529675,
            "txid": "ddbe1dce4537926b6cf5bc1e222e5cd32de224cf346ca89251c127ce32226f30",
            "walletconflicts": [],
            "time": 1607529401,
            "timereceived": 1607529401,
            "bip125-replaceable": "no",
            "comment": " ",
            "to": "seans outpost",
            "abandoned": false
        }
    ],
    "error": null,
    "id": "curltest"
}

How can I get sender's address?

4
  • 1
    What do you need the sender address for? Bitcoin doesn't really have such a concept. There are approximations but they're often wrong. If the goal is distinguishing multiple payments to determine who paid, the best practice is giving a different receiving address to for every payment. Dec 14, 2020 at 19:04
  • @PieterWuille Certain regulatory reporting schemes require a list of the sending addresses. The sending addresses can definitely be discovered for a given txid and would be considered pertinent information as shown by every blockchain explorer.
    – Ron
    Mar 4, 2022 at 0:12
  • 2
    What if the transaction is a payjoin/coinjoin? The "apparent" sending addresses would belong to a multitude of unrelated people. If funds are withdrawn from an exchange, the apparent sending address may belong to a different exchange customer. Just because data is visible does not mean it is meaningul. Mar 4, 2022 at 1:00
  • @PieterWuille I agree with your statement that "visible does not mean it is meaningful", but that is irrelevant to the original question about how to achieve this in a technical manner (not what the significance of the result is). It seems you agree that the concept exists by having a conversation about its meaningfulness or usability. If the transaction is coinjoin then the sending addresses can still be enumerated in the same way. The connections between inputs and outputs in coinjoin transactions may still be inferred through certain heuristics.
    – Ron
    Mar 10, 2022 at 1:12

2 Answers 2

1

Despite how it looks on most block explorers, Bitcoin doesn't really have a concept of a "sender address", at least not on the raw transaction level. What a transaction has is inputs and what block explorers do is go look up those inputs and guess the address that was used to create those UTXOs.

You might find these related questions useful (just search this site for "sender address"):

How to findout the sender of a transaction

Sender address from DecodeRawTransaction (C#)

0

To get the sender address from Bitcoin Core, you will have to track additional information about the blockchain by setting txindex=1 in the configuration file. This is because the sending address of the transaction in question is only associated with the previous transaction. Setting txindex=1 configures Bitcoin Core to maintain the entire transaction index, beyond what pertains to your wallet or read-only addresses, allowing you to call getrawtransaction on any txid.

Once you have properly configured and synced Bitcoin Core, you can retrieve the sending address(es) of a transaction by looking through each input tx using decoderawtransaction(getrawtransaction(txid)) (code pulled from this answer):

txid = <relevant transaction id>
addresses = []
raw_tx = decoderawtransaction(getrawtransaction(txid))
for(input in raw_tx['vin']) {
  input_raw_tx = decoderawtransaction(getrawtransaction(input['txid']))
  addresses.push(input_raw_tx['vout'][input['vout']]['scriptPubKey']['addresses'][0])
}

Many blockchain explorers have free low-volume API access and you can just query their data instead of maintaining a full txindex node. Two that come to mind are Blockchair and BlockCypher (BlockCypher even includes all the sender addresses in their tx endpoint so you can retrieve these with a single API call instead of querying each input tx from Blockchair like you would need to with Bitcoin Core).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.