Bitcoin: parsing Blockchain API using JSON

0 votes

The Bitcoin TX has 10 inputs from 10 adresses. I want to retreive these adresses using the API.

The following code only retrieves the first adress instead of all 10:

import json

import urllib2

import sys



#Random BTC adress (user input)

btc_adress = ("1GA9RVZHuEE8zm4ooMTiqLicfnvymhzRVm")


#API call to blockchain

url = "https://blockchain.info/address/"+(btc_adress)+"?format=json"

json_obj = urllib2.urlopen(url)

data = json.load(json_obj)


#Put tx's into a list

txs_list = []

for txs in data["txs"]:

    txs_list.append(txs)


#Cut the list down to 5 recent transactions

listcutter = len(txs_list)

if listcutter >= 5:

    del txs_list[5:listcutter]


# Get number of inputs for tx

recent_tx_1 = txs_list[1]

total_inputs_tx_1 = len(recent_tx_1["inputs"])

The block below needs to put all 10 input adresses in the list 'Output_adress'. It only does so for the first one;

output_adress = []

output_adress.append(recent_tx_1["inputs"][0]["prev_out"]["addr"])


print output_address
Aug 22, 2018 in Blockchain by slayer
• 29,050 points
176 views

1 answer to this question.

0 votes

Because you only add one address to it. Change it to this:

output_adress = []

for i in xrange(len(recent_tx_1["inputs"])):

    output_adress.append(recent_tx_1["inputs"][i]["prev_out"]["addr"])

print output_adress

answered Aug 22, 2018 by digger
• 27,620 points

Related Questions In Blockchain

+1 vote
1 answer

Transaction using Blockchain wallet APi

Each transaction requires a fee to be ...READ MORE

answered Jun 19, 2018 in Blockchain by Perry
• 17,010 points
35 views
0 votes
1 answer

Not able to send payments using Blockchain API.

Try the following code. It should help ...READ MORE

answered Jul 31, 2018 in Blockchain by slayer
• 29,050 points
33 views
+1 vote
1 answer
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,620 points
2,128 views
0 votes
1 answer
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 27,620 points
182 views
0 votes
1 answer

Bitcoin: error parsing json

Make these changes in your code: json="'{" to ...READ MORE

answered Aug 22, 2018 in Blockchain by digger
• 27,620 points
120 views
0 votes
1 answer

What is blockchain apart from bitcoin?

Blockchain is a decentralized database where the ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 27,620 points
12 views