We will use Bitcoin RPC methods to get mempool data
getrawmempool method to be specific Open terminal/cmd and copy-paste the following:
how to access bitcoin mempool how to get pending transactions from bitcoin
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawmempool", "params": [true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawmempool", "params": [true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawmempool", "params": [true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
Replace
QUICKNODE_BITCOIN_URL with your Bitcoin node’s HTTPS URL, which we got in the last step. Above is a
cURL request to our node along with the getrawmempool method.
The output should be similar to this.
Now let us understand the output body. The above method gives out a list of pending transactions currently in the mempool. We will take out a single transaction and go through each field.
how to access bitcoin mempool how to get pending transactions from bitcoin
{
"result": {
"2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3": {
"fees": {
"base": 0.00111999,
"modified": 0.00111999,
"ancestor": 0.00111999,
"descendant": 0.00111999
},
"size": 90826,
"fee": 0.00111999,
"modifiedfee": 0.00111999,
"time": 1629052793,
"height": 695936,
"descendantcount": 1,
"descendantsize": 90826,
"descendantfees": 111999,
"ancestorcount": 1,
"ancestorsize": 90826,
"ancestorfees": 111999,
"wtxid": "b3b49bb3dcae483d579710a2e1f9c7ed585ab35e2a8cb941ff8cb27ea8adec20",
"depends": [],
"spentby": [],
"bip125-replaceable": false
}
}
}
{
"result": {
"2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3": {
"fees": {
"base": 0.00111999,
"modified": 0.00111999,
"ancestor": 0.00111999,
"descendant": 0.00111999
},
"size": 90826,
"fee": 0.00111999,
"modifiedfee": 0.00111999,
"time": 1629052793,
"height": 695936,
"descendantcount": 1,
"descendantsize": 90826,
"descendantfees": 111999,
"ancestorcount": 1,
"ancestorsize": 90826,
"ancestorfees": 111999,
"wtxid": "b3b49bb3dcae483d579710a2e1f9c7ed585ab35e2a8cb941ff8cb27ea8adec20",
"depends": [],
"spentby": [],
"bip125-replaceable": false
}
}
}
{
"result": {
"2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3": {
"fees": {
"base": 0.00111999,
"modified": 0.00111999,
"ancestor": 0.00111999,
"descendant": 0.00111999
},
"size": 90826,
"fee": 0.00111999,
"modifiedfee": 0.00111999,
"time": 1629052793,
"height": 695936,
"descendantcount": 1,
"descendantsize": 90826,
"descendantfees": 111999,
"ancestorcount": 1,
"ancestorsize": 90826,
"ancestorfees": 111999,
"wtxid": "b3b49bb3dcae483d579710a2e1f9c7ed585ab35e2a8cb941ff8cb27ea8adec20",
"depends": [],
"spentby": [],
"bip125-replaceable": false
}
}
}
Explanation of the above JSON output:
Line 3: This is the transaction id by which a transaction on the blockchain is identified.
Line 4-9: Transaction fee breakdown.
Line 10: Size of the transaction as per
BIP 141.
Line 11: Transaction fee in BTC (bitcoin).
Line 12: Transaction fee with fee deltas used for mining priority.
Line 13: Time at which the transaction entered in the pool in seconds since 1 Jan 1970 GMT.
Line 14: Height of the blockchain (latest block) when transaction entered the pool.
Line 16: Size of all the descendent transactions in mempool.
Line 17: Modified fees of all the descendent transactions in mempool.
Line 19: Size of all the ancestor transactions in mempool.
Line 20: Modified fees of all the ancestor transactions in mempool.
Line 22: If an unconfirmed transaction is used as input for this transaction, it is to be entered here.
Line 23: If another unconfirmed transaction is using data from this transaction, it must be entered here.
Line 24: A Boolean value showing that whether the transaction can be replaced due to
BIP 125.
Now to get the actual transaction data we will have to use another method
getrawtransaction which will return information about a particular transaction. Copy-paste the following in your terminal/cmd:
how to access bitcoin mempool how to get pending transactions from bitcoin
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawtransaction", "params": ["2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3", true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawtransaction", "params": ["2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3", true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawtransaction", "params": ["2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3", true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
Replace
QUICKNODE_BITCOIN_URL with your Bitcoin node’s HTTPS URL, which we got in the last step. Above is a
cURL request to our node along with the getrawtransaction method. To get this, we will ping our node to resolve the method. We have to pass two parameters for this method. The first is the transaction id of the transaction to be queried. The second is a boolean value which, if set false, returns a string; otherwise, it returns a JSON object.
We have set the second parameter as ‘true’, so the output should look like this.
Explanation of the transaction object pasted
here:
Line 3: Transaction id by which a transaction on the blockchain is identified (same as provided).
Line 4: Transaction hash which from txid for witness transactions.
Line 5: Size of the transaction as per
BIP 141.
Line 6: Virtual size of the transaction which from size for witness transactions.
Line 8: Lock time is specified as a block number. If a lock time is mentioned, then that transaction can only be added to a block if the lock time block has been passed. For example, if the lock time is mentioned as 30, miners can only pick up the transaction after block number 30 has been mined.
Line 9-20: Vin shows the list of transactions in mempool this particular transaction is using as input.
Line 21-33: Vout shows the list of transactions in mempool using this particular transaction as input.
Line 34: Block hash, null here as the transaction is not confirmed yet.
Line 35: Number of confirmations the transaction has passed.
Line 36: Time at which the transaction entered in the pool in seconds since 1 Jan 1970 GMT.
Line 37: Time at which block was mined in which the transaction was added, null here since the transaction is pending.
Line 38: Serialized, hex-encoded data for 'txid'
By analyzing the above data we can understand in and outs of a Bitcoin transaction. Bitcoin transactions are pretty complex, but getrawtransaction method gives out the raw transaction information which is easy to look at and understand.