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,350 points
2,959 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
• 26,740 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,100 points
464 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,350 points
437 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
• 26,740 points
43,810 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
673 views
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
• 26,740 points
2,172 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
• 26,740 points
1,190 views
+1 vote
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
• 26,740 points
574 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP