How to query blockchain.info?

1

I need to query blockchain.info with an address and determine how much is there, ignoring transactions that don't have 3 confirmations.

Can anyone give me a hint how to do this?

Claudiu

Posted 2013-04-19T12:43:32.313

Reputation: 19

What? could you rephrase?o0'. 2013-04-19T13:24:03.670

1

This sounds a bit like an XY problem. I'm guessing that you want to take payments, right?

Nick ODell 2013-04-19T17:05:57.593

1

Have you read through http://blockchain.info/api?

ripper234 2013-04-19T17:45:48.597

Answers

3

Get the block count:

http://blockchain.info/q/getblockcount

Subtract 3 from that number.

Get the transactions from the address you're looking for:

http://blockchain.info/address/$bitcoin_address?format=json&limit=50&offset=0

This returns 50 transactions by default, change the 'limit' value to wherever you might need it to be. Setting 'offset' to 5 will allow you to skip the first 5 transactions. Make sure you don't set offset to something greater than the total number of transactions on a particular address, it won't ever return anything.

Then set up your code to ignore any transaction that's newer than 3 blocks ago.

Morichalion

Posted 2013-04-19T12:43:32.313

Reputation: 31

2

You can do this in two API calls, plus some filtering:

  1. Get the current block height from http://blockchain.info/latestblock
  2. Get the list of transactions for the address from http://blockchain.info/address/$hash_160?format=json
  3. Filter transactions from #2 where the height is less than current block height minus 3.

Rough Ruby code:

require 'open-uri'
require 'json'
require 'pp'

desired_address = '1dice7W2AicHosf5EL3GFDUVga7TgtPFn' #high traffic address good for example code!
get_transactions_with_minimum_of_n_confirmations = 3

latestblock = JSON.parse open('http://blockchain.info/latestblock').read
address = JSON.parse open("http://blockchain.info/address/#{desired_address}?format=json").read

current_block_height = latestblock["height"]
pp address["txs"].select {|tx| tx["block_height"] < (current_block_height - get_transactions_with_minimum_of_n_confirmations) }

Keep in mind that you're going to retrieve a list of ALL transactions involving that address. It'd be nice of Blockchain.info let you specify a minimum number of confirmations to limit transactions to on the address call.

Colin Dean

Posted 2013-04-19T12:43:32.313

Reputation: 6 559