How to get the Input Address from vin where only a txid is given (Insight-Api)

5

2

I like to find the Input Address and Amount for a vin like this:

"vin": [
    {
        "txid": "e3f0e88ce224d342a0189c1b9d2fd488d8bda2f303dbe1e1dbbaa5f51d9f4a53",
        "vout": 1,
        "scriptSig": {
            "asm": "3044022036c454ee41d67ee7c00fade55d57b573794916c1e1d9f301a038547daa5fcc0502202c99917b5590adf2ede1b8e3a6773369690a268c7b445664223ec8f92288e81e010272491cc9c405bfdc35f766bd849ddc58268088c202425cec224aa05cbf8547be"
        },
        "sequence": 4294967295,
        "n": 0,
        "unconfirmedInput": 1
    }
]

This is from txid: f4f2ddb44a8d155bc795e3e7497714fd6a1f035a6438b22403a7faa67012b9ec

Thanks

thepiwo

Posted 2014-05-23T12:58:49.730

Reputation: 73

Answers

4

First, use the API to get the information on the txid.

/api/tx/e3f0e88ce224d342a0189c1b9d2fd488d8bda2f303dbe1e1dbbaa5f51d9f4a53

This result will include all of the details you're looking for. Here are the parts that you're asking about. The n here corresponds to the vout number above, I believe, and the value and addresses values are the input amount and address.

"value": "2405.38864196",
"n": 1,
"scriptPubKey": {
    ...
    "addresses": [
        "1NG1nT2ZuFw47f41mGjYpPp7J837yTQZhB"
    ]
},
...

Tim S.

Posted 2014-05-23T12:58:49.730

Reputation: 4 159

So when I'm reading block 255 145 and I want to know from where is taken the input I have to rescan all the previous block looking for that TX ? :o (I'm parsing the blockchain mannualy)sliders_alpha 2017-12-11T15:53:29.957

@sliders_alpha Yeah, potentially. If you want to be more efficient, as you scan the blockchain going forward, keep a list of transaction id's and which block they came in.Tim S. 2017-12-16T21:15:17.773

1

You can code it, Python 2.7 implementation for same is:

#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ ="cryptoKTM"

import requests,json
url="http://username:password@server:PORT"
payload={}
payload = {"jsonrpc":1,"id":"curltext"}
txid= "10ff6ff5bdc73d7bb6d711c6896618a05479d061e67f576a0950328c1389035f"
addresses = []
payload["method"]="getrawtransaction"
payload["params"]=[txid,1]
response = requests.post(url,json.dumps(payload))
response =response.json()
response= response["result"]["vin"]
for data in response:
    raw_tx1=data["txid"]
    vout_int=data["vout"]
    payload["params"]=[raw_tx1,1]
    response_ = requests.post(url,json.dumps(payload))
    response_= response_.json()
    data_ =response_["result"]["vout"]
    for item in data_:
        if item["n"] == vout_int:
            json_data ={}
            json_data[item["scriptPubKey"]["addresses"][0]] = item["value"]
            addresses.append(json_data)

print addresses

cryptoKTM

Posted 2014-05-23T12:58:49.730

Reputation: 489