Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: OmegaStarScream on July 04, 2016, 03:12:41 PM



Title: How to get transaction info in Real-Time ?
Post by: OmegaStarScream on July 04, 2016, 03:12:41 PM
I want to know how it's possible to get a transaction info in real time ?

When I say "In real time" what I mean is , once the transaction happens and gets added to the Blockchain.

How wallets are doing it ? are they checking the blockchain each x seconds or something like that ? If you didn't understand due to my poor english or something , please let me know so I explain more.


Title: Re: How to get transaction info in Real-Time ?
Post by: achow101 on July 04, 2016, 03:26:20 PM
Wallets listen to other nodes. When a block is added to the blockchain, it is broadcast from one node to all of its peers. When a wallet receives that block, it checks the transactions in the block to see if it includes a transaction that it is tracking. If it does, then it updates its database. Then the wallet, if it is a node, broadcasts the block to all of its peers.


Title: Re: How to get transaction info in Real-Time ?
Post by: unamis76 on July 04, 2016, 03:29:20 PM
I remember there were tools for this. Like this (https://bitcointalk.org/index.php?topic=373490.0) one. Never tried it tho.


Title: Re: How to get transaction info in Real-Time ?
Post by: OmegaStarScream on July 04, 2016, 03:32:26 PM
Wallets listen to other nodes. When a block is added to the blockchain, it is broadcast from one node to all of its peers. When a wallet receives that block, it checks the transactions in the block to see if it includes a transaction that it is tracking. If it does, then it updates its database. Then the wallet, if it is a node, broadcasts the block to all of its peers.

So I suppose it's impossible to make a real time application If I'm using an API of Blockchain or BlockTrail , correct ?
I should run Bitcoind instead ? Since if I use an API I will have limited requests per x minutes and It's impossible to get in real time.


Title: Re: How to get transaction info in Real-Time ?
Post by: amaclin on July 04, 2016, 03:42:29 PM
Start from this example
https://github.com/sebicas/bitcoin-sniffer


Title: Re: How to get transaction info in Real-Time ?
Post by: achow101 on July 04, 2016, 03:51:42 PM
Wallets listen to other nodes. When a block is added to the blockchain, it is broadcast from one node to all of its peers. When a wallet receives that block, it checks the transactions in the block to see if it includes a transaction that it is tracking. If it does, then it updates its database. Then the wallet, if it is a node, broadcasts the block to all of its peers.

So I suppose it's impossible to make a real time application If I'm using an API of Blockchain or BlockTrail , correct ?
I should run Bitcoind instead ? Since if I use an API I will have limited requests per x minutes and It's impossible to get in real time.
No, not necessarily. Some APIs have streaming sockets. This means that your application connects to the API and when the API learns of a block, it broadcasts it to your application as long as the connection remains open. This will be in real time.


Title: Re: How to get transaction info in Real-Time ?
Post by: OmegaStarScream on July 04, 2016, 03:58:18 PM
Wallets listen to other nodes. When a block is added to the blockchain, it is broadcast from one node to all of its peers. When a wallet receives that block, it checks the transactions in the block to see if it includes a transaction that it is tracking. If it does, then it updates its database. Then the wallet, if it is a node, broadcasts the block to all of its peers.

So I suppose it's impossible to make a real time application If I'm using an API of Blockchain or BlockTrail , correct ?
I should run Bitcoind instead ? Since if I use an API I will have limited requests per x minutes and It's impossible to get in real time.
No, not necessarily. Some APIs have streaming sockets. This means that your application connects to the API and when the API learns of a block, it broadcasts it to your application as long as the connection remains open. This will be in real time.

Oh , I see , It make sense as well ! Do you know any API that do that ? I suppose Blockchain don't?
I just googled ,It seems like they do have it : https://blockchain.info/api/api_websocket , thanks for your help mate ! I appreciate it!


Title: Re: How to get transaction info in Real-Time ?
Post by: achow101 on July 04, 2016, 04:02:39 PM
Oh , I see , It make sense as well ! Do you know any API that do that ? I suppose Blockchain don't?
I just googled ,It seems like they do have it : https://blockchain.info/api/api_websocket , thanks for your help mate ! I appreciate it!
blocktrail has one: https://www.blocktrail.com/api/docs#api_webhooks
so does blockcypher: http://dev.blockcypher.com/#events-and-hooks


Title: Re: How to get transaction info in Real-Time ?
Post by: OmegaStarScream on July 04, 2016, 04:08:20 PM
Oh , I see , It make sense as well ! Do you know any API that do that ? I suppose Blockchain don't?
I just googled ,It seems like they do have it : https://blockchain.info/api/api_websocket , thanks for your help mate ! I appreciate it!
blocktrail has one: https://www.blocktrail.com/api/docs#api_webhooks
so does blockcypher: http://dev.blockcypher.com/#events-and-hooks

Yes I found the one of BlockTrail , It's sad that most of them don't support C# as should be (no libraries etc... If there is any there are most likely out dated).
Anyway , thank you for your help mate ! I really appreciate it .


Title: Re: How to get transaction info in Real-Time ?
Post by: belcher on July 04, 2016, 04:43:39 PM
Depends what you're trying to actually do.

The best way is probably to run a full node and configure -blocknotify to alert your script when a new block arrives.


Title: Re: How to get transaction info in Real-Time ?
Post by: Ned Kelly on July 10, 2016, 05:05:52 PM
There are several subtleties with an answer to you question.

When I say "In real time" what I mean is , once the transaction happens and gets added to the Blockchain.

The block on the top of blockchain could be an orphan block. As the result, some transactions can become absent from blockchain latter.

 If it's not a concern and you can tolerate some such transactions. You can get transactions even faster.
Use
Code:
getrawmempool
in Bitcoin core client. However, it's possible that not all network transactions will be in your memory pool.
Also, some of those transactions could be refused by miners later. For example, low or zero fee.