Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: stepancher on July 16, 2018, 07:25:03 AM



Title: Fetch Bitcoin mempool transactions
Post by: stepancher on July 16, 2018, 07:25:03 AM
I need to see bitcoin transactions before they were included in the block. Interested in transactions to specific addresses.

After some research, it became clear that the mempool is synchronized heterogeneous. And it is not necessary that the transaction I am interested in, in principle, will be on my node..

Moreover, from second to second, the pool of transactions contains a completely different number of transactions, so even to have time to read them all and filter it is not possible. Or could someone have done it?

Are there people who have faced such a challenge? Fetch transactions in mempool


Title: Re: Fetch Bitcoin mempool transactions
Post by: bob123 on July 16, 2018, 07:47:06 AM
I need to see bitcoin transactions before they were included in the block. Interested in transactions to specific addresses.
After some research, it became clear that the mempool is synchronized heterogeneous. And it is not necessary that the transaction I am interested in, in principle, will be on my node..

While it is not 100% sure that your node will get every transaction, the probability is very high.
Nodes do relay received transactions to every other node (exceptions do exist: non-standard tx, maliciously edited software, ...) .
Each node receives the transactions in a different order (and at a different time +/- a few seconds usually).
 


Moreover, from second to second, the pool of transactions contains a completely different number of transactions, so even to have time to read them all and filter it is not possible. Or could someone have done it?
Are there people who have faced such a challenge? Fetch transactions in mempool

Well, if you try it to do by hand you just have to open any block explorer (e.g. blockchain.info (https://www.blockchain.com/de/explorer)), enter the address and refresh every second to see any incoming transactions to this particular address (in blockchain.info's mempool).

The smoother alternative would be to write a small script (e.g. bash / python / .. ) and query your own node (or an online service API) each x seconds and perfom an action to inform you (e.g. console log, window popup, email, etc..).


Title: Re: Fetch Bitcoin mempool transactions
Post by: stepancher on July 17, 2018, 04:19:16 AM
And there is a subject experience?

First, we get a list of transaction hashes in the ampoule (GetRawMemPool), then we try to get the data for EACH of them (GetMemPoolEntry)

From what we've seen, there are a few challenges:
1. GetMemPoolEntry-returns mempool data for given transaction (must be in mempool) - and transactions are constantly updated. Accordingly, the received hash function GetRawMemPool-may not be in mempool in a second. Is that so?
2. Get Mem Pool Entry-returns data for one transaction.. And a lot of them...it turns out we throw on the node tons of small RPC calls, it does not die?


Title: Re: Fetch Bitcoin mempool transactions
Post by: bob123 on July 17, 2018, 09:32:55 AM
From what we've seen, there are a few challenges:
1. GetMemPoolEntry-returns mempool data for given transaction (must be in mempool) - and transactions are constantly updated. Accordingly, the received hash function GetRawMemPool-may not be in mempool in a second. Is that so?

GetMemPoolEntry (txid) returns the mempool data for the given transaction (Documentation: https://bitcoincore.org/en/doc/0.16.0/rpc/blockchain/getmempoolentry/ (https://bitcoincore.org/en/doc/0.16.0/rpc/blockchain/getmempoolentry/)).

Transactions are not updated. Once the transaction is in your mempool, it will stay there until either (1) it gets confirmed and you receive the block or (2) your node drops it from the mempool (variety of reasons lead to this, e.g. not included into a block for x weeks (standard: 2 weeks)).

The mempool gets updated constantly (adding/removing transactions to it).

GetRawMempool returns all transaction id's of the TX inside your mempool. Note: This is NOT a hash function (https://en.wikipedia.org/wiki/Hash_function). It is a simple RPC call (Documentation: https://bitcoincore.org/en/doc/0.16.0/rpc/blockchain/getrawmempool/ (https://bitcoincore.org/en/doc/0.16.0/rpc/blockchain/getrawmempool/) ).




2. Get Mem Pool Entry-returns data for one transaction.. And a lot of them...it turns out we throw on the node tons of small RPC calls, it does not die?

I don't really understand your question/concern.
GetMemPoolEntry (txid) does return all necessary information regarding a transaction (txid, size, fee, ...).

What exactly is your concern? Are you trying to query your node with a massive amount of RPC calls ?
Is your concern whether how much RPC calls your node can answer in a given time ?  In this case it depends on your specific setup (hardware, OS, .. ).


Title: Re: Fetch Bitcoin mempool transactions
Post by: blacknight789 on July 19, 2018, 12:24:42 PM
Node is more likely to get a deal. However, block exploratory can be used. It will not be necessary to keep filtering well if you have a memory role.


Title: Re: Fetch Bitcoin mempool transactions
Post by: bitcoindigger71 on July 19, 2018, 01:49:33 PM
I think Mempool are diverse its clear to all after conducting some research. The most important thing is the pool transaction process in differs from other transaction. The most important things is mempool get update rapidly taat resolve the transaction process.


Title: Re: Fetch Bitcoin mempool transactions
Post by: SoliDCoiNs777 on July 19, 2018, 08:13:11 PM
I think it will happened but it is not important to get every transaction in your node timely it will be in different order.


Title: Re: Fetch Bitcoin mempool transactions
Post by: Tmcrypto on July 19, 2018, 09:29:16 PM
If we want to go for the classical method, then we need to open a blockchain, put the desired address and then refresh every now and then to see the inflow of transactions to the input address. An easier alternative is to use python and query your own nodes. Experience needs to be considered in the latter.


Title: Re: Fetch Bitcoin mempool transactions
Post by: GreenEarth22 on August 06, 2018, 06:32:45 PM
It is possible to view the unconfirmed transactions. Transactions returns in your memory pool until they are confirmed. So, that’s how you can see the unconfirmed transactions.


Title: Re: Fetch Bitcoin mempool transactions
Post by: TheArchaeologist on August 06, 2018, 07:23:14 PM
I need to see bitcoin transactions before they were included in the block. Interested in transactions to specific addresses.

Can you tell a bit more about what you want to achieve?

Anyway you could do it like this by using the bitcoin-cli route when running a full node:

Code:
bitcoin-cli getrawmempool

Returns a bunch of transaction id's currently in the mempool:

[
  "6cf5d95f37a1cca36fa43fa719119fe9f77028ba723829e85651ace4ad5d8f19",
  "11a1bd02f9e742604f30b6e2365ca1e8ae96f6a5aafb44c175e96d685ddccd99",
  "13fd3c38da7df2f0905747222fd8b1b5bd109a015c3c122a9f53dcf5ffdfcce3",
  ........................
]

Next get some info about the first transaction:

Code:
bitcoin-cli getrawtransaction 6cf5d95f37a1cca36fa43fa719119fe9f77028ba723829e85651ace4ad5d8f19

Returns the raw transaction:
0100000001e740376b175694ee9a7a1423439b3db7f742fdfe0d25be703a22224b19dd25f8010000006b483045022100a24327625d18863b2abfd2ab439ea5dc5fd8103ed81a0da44baacdb8b1cb94ab02202231a9da46fb6b6bf1847c1fe8bb5d78e3658d2c32a670b961b6a849102c2bed01210223eea9ed5a727a10a0c880e9c903ba0d9aff973ece8501ecb75e1f776ee64459ffffffff0286f0ad16000000001976a914d5315454514b6c81d52341b7ed8ebcaa8424d37888ac1ad2e000000000001976a91402dd14395dbd7311c02179746d59882131fbe25588ac00000000

And finally decode that transaction:
Code:
bitcoin-cli decoderawtransaction 0100000001e740376b175694ee9a7a1423439b3db7f742fdfe0d25be703a22224b19dd25f8010000006b483045022100a24327625d18863b2abfd2ab439ea5dc5fd8103ed81a0da44baacdb8b1cb94ab02202231a9da46fb6b6bf1847c1fe8bb5d78e3658d2c32a670b961b6a849102c2bed01210223eea9ed5a727a10a0c880e9c903ba0d9aff973ece8501ecb75e1f776ee64459ffffffff0286f0ad16000000001976a914d5315454514b6c81d52341b7ed8ebcaa8424d37888ac1ad2e000000000001976a91402dd14395dbd7311c02179746d59882131fbe25588ac00000000

Returns:
{
  "txid": "6cf5d95f37a1cca36fa43fa719119fe9f77028ba723829e85651ace4ad5d8f19",
  "hash": "6cf5d95f37a1cca36fa43fa719119fe9f77028ba723829e85651ace4ad5d8f19",
  "version": 1,
  "size": 226,
  "vsize": 226,
  "locktime": 0,
  "vin": [
    {
      "txid": "f825dd194b22223a70be250dfefd42f7b73d9b4323147a9aee9456176b3740e7",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100a24327625d18863b2abfd2ab439ea5dc5fd8103ed81a0da44baacdb8b1cb94ab02202231a9da46fb6b6bf1847c1fe8bb5d78e3658d2c32a670b961b6a849102c2bed[ALL] 0223eea9ed5a727a10a0c880e9c903ba0d9aff973ece8501ecb75e1f776ee64459",
        "hex": "483045022100a24327625d18863b2abfd2ab439ea5dc5fd8103ed81a0da44baacdb8b1cb94ab02202231a9da46fb6b6bf1847c1fe8bb5d78e3658d2c32a670b961b6a849102c2bed01210223eea9ed5a727a10a0c880e9c903ba0d9aff973ece8501ecb75e1f776ee64459"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 3.80498054,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 d5315454514b6c81d52341b7ed8ebcaa8424d378 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914d5315454514b6c81d52341b7ed8ebcaa8424d37888ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1LSG2Kzf1mYSboFzKW2bsRzRP5TbcHvDPG"
        ]
      }
    },
    {
      "value": 0.14733850,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 02dd14395dbd7311c02179746d59882131fbe255 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a91402dd14395dbd7311c02179746d59882131fbe25588ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1G9CDsTx2mUcB4NcPKW5uqp5tPF8Gc6Q9"
        ]
      }
    }
  ]
}

So you can see a value of 3.80498054 was transferred to 1LSG2Kzf1mYSboFzKW2bsRzRP5TbcHvDPG in that transaction as well as a value of 0.14733850 to 0.14733850.

Put it all in a script and it shouldn be too hard to monitor the transactions in the mempool for specific addresses.


Title: Re: Fetch Bitcoin mempool transactions
Post by: Thirdspace on August 06, 2018, 10:57:47 PM
I need to see bitcoin transactions before they were included in the block. Interested in transactions to specific addresses.
I'm not sure what you are trying to do, but you can check bitaps.com explorer
this explorer relays and keeps almost all records when another nodes seems to drop it 
look at this address https://bitaps.com/1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T
it shows complete history including all unconfirmed and double spend attempt transactions

After some research, it became clear that the mempool is synchronized heterogeneous. And it is not necessary that the transaction I am interested in, in principle, will be on my node..
normally all major nodes will have about the same mempool transactions
for some reasons they might have different set of unconfirmed transactions in mempool
the reason is each node may have different rules on keeping and relaying them
another possibility is mempool size limitation but this is unlikely for major nodes