<p>I have created a simple php function with my basic knowledge of php.
here</p>

<blockquote>
  <p>function get_tx_confirmation($tx_hash_id){
      $raw_lastest_block= json_decode(file_get_contents("<a href="https://blockchain.info/latestblock" rel="nofollow noreferrer">https://blockchain.info/latestblock</a>"), true);
   $lastest_block=$raw_lastest_block["height"];<br>
   $raw_tx=json_decode(file_get_contents("<a href="https://blockchain.info/rawtx/" rel="nofollow noreferrer">https://blockchain.info/rawtx/</a>$tx_hash_id"), true);
   $tx_block_height=$raw_tx["block_height"];
       $confirmations = $lastest_block - $tx_block_height +1;
  return $confirmations;<br>
      }</p>
</blockquote>

CC BY-SA 3.0
2017-01-29T15:13:24.497Z
This is just to get the amount of transactions using the hash id
Meet Electrode
CC BY-SA 3.0
2017-01-29T15:11:46.967Z
2017-01-29T15:11:46.967Z
Meet Electrode
<p>If a transaction returned from the <code>http://blockchain.info/rawtx/$tx_hash</code> endpoint has a confirmation, it will have a <code>block_height</code> member. You can then calculate roughly its number of confirmations by subtracting that value from the latest height retrieved from the <code>http://blockchain.info/latestblock</code> endpoint.</p>

<p>Code example, in Ruby:</p>

<pre><code>#!/usr/bin/env ruby
require "open-uri"
require "json"
# call this script with `ruby block_height.rb &lt;tx_hash&gt;`
tx = ARGV.shift
puts "Getting info for #{tx}..."
j = JSON.parse open("http://blockchain.info/rawtx/#{tx}").read
if j["block_height"]
  b = JSON.parse open("http://blockchain.info/latestblock").read
  puts "%d confirmations" % (b["height"] - j["block_height"] + 1)
else
  time_since = Time.now.gmtime.to_i - j["time"]
  puts "It's been #{time_since} seconds since the transaction was created."
  puts "It's not been ten minutes yet!" if time_since &lt; 600
  puts "It's due any time now." if time_since &gt;= 600
end
</code></pre>

<p>Calculating the transaction fee is best done by summing the inputs and outputs of a transaction, then subtracting the inputs from the outputs. Difference is the transaction fee.</p>

CC BY-SA 3.0
2013-01-28T15:51:19.513Z
Hi Colin! Thanks a lot! Could you expand a bit on the block_height part?
flaab
CC BY-SA 3.0
2013-01-29T02:54:53.017Z
Added a code example for you.
Colin Dean
CC BY-SA 3.0
2015-11-02T06:37:20.743Z
verifies but just out of curiosity, how do I explain the relations between the number of confirmations, the tx block height and the latest block height?
user237419
CC BY-SA 3.0
2015-11-06T19:35:46.883Z
number of confirmations = latest block height - tx block height
Colin Dean
CC BY-SA 3.0
2013-01-28T04:50:10.960Z
2013-01-29T02:54:42.297Z
2013-01-29T02:54:42.297Z
Colin Dean
<p>How can I know if any given transaction has confirmations and has paid the miner's fee, using the <a href="https://blockchain.info/api/blockchain_api">BlockChain.info DATA API</a>?</p>

<confirmations><blockchain.info><transaction-fees>
How can I determine the number of confirmations of a transaction and its fee using the Blockchain.info DATA API?
flaab
# How can I determine the number of confirmations of a transaction and its fee using the Blockchain.info DATA API?

(Asked by: username_0 on 2013-01-28)

How can I know if any given transaction has confirmations and has paid the miner's fee, using the [BlockChain.info DATA API](https://blockchain.info/api/blockchain_api)?

**Tags:** confirmations, blockchain.info, transaction-fees


---

## 2 answers

### Answer by username_2 on 2013-01-28. Score: 7 | Accepted answer

If a transaction returned from the http://blockchain.info/rawtx/$tx_hash endpoint has a confirmation, it will have a block_height member. You can then calculate roughly its number of confirmations by subtracting that value from the latest height retrieved from the http://blockchain.info/latestblock endpoint.
Code example, in Ruby:
#!/usr/bin/env ruby
require "open-uri"
require "json"
# call this script with `ruby block_height.rb `
tx = ARGV.shift
puts "Getting info for #{tx}..."
j = JSON.parse open("http://blockchain.info/rawtx/#{tx}").read
if j["block_height"]
  b = JSON.parse open("http://blockchain.info/latestblock").read
  puts "%d confirmations" % (b["height"] - j["block_height"] + 1)
else
  time_since = Time.now.gmtime.to_i - j["time"]
  puts "It's been #{time_since} seconds since the transaction was created."
  puts "It's not been ten minutes yet!" if time_since < 600
  puts "It's due any time now." if time_since >= 600
end

Calculating the transaction fee is best done by summing the inputs and outputs of a transaction, then subtracting the inputs from the outputs. Difference is the transaction fee.

> **Comments:**
> **username_0**: Hi Colin! Thanks a lot! Could you expand a bit on the block_height part?  
> **username_2**: Added a code example for you.  
> **username_3**: verifies but just out of curiosity, how do I explain the relations between the number of confirmations, the tx block height and the latest block height?  
> **username_2**: number of confirmations = latest block height - tx block height  

---

### Answer by username_1 on 2017-01-29. Score: 2

I have created a simple php function with my basic knowledge of php.
here

> function get\_tx\_confirmation($tx\_hash\_id){
> $raw\_lastest\_block= json\_decode(file\_get\_contents("<https://blockchain.info/latestblock>"), true);
> $lastest\_block=$raw\_lastest\_block["height"];  
> $raw\_tx=json\_decode(file\_get\_contents("<https://blockchain.info/rawtx/>$tx\_hash\_id"), true);
> $tx\_block\_height=$raw\_tx["block\_height"];
> $confirmations = $lastest\_block - $tx\_block\_height +1;
> return $confirmations;  
> }

> **Comments:**
> **username_1**: This is just to get the amount of transactions using the hash id  

---

