3

I have bitcoin full node on the server. I need to notify when new incoming transaction is arrive into a bitcoin address. Is there any RPC will help to achieve my goal ...

Any help is appreciable. Thank you

0

4 Answers 4

4

Try using ZeroMQ to listen to transaction event. You can subscribe to hashtx or rawtx events.

Here is a nodejs example taken from this great guide by GR0KCHAIN: https://bitcoindev.network/accessing-bitcoins-zeromq-interface/

var zmq = require('zmq')
  , sock = zmq.socket('sub')
  , RpcClient = require('bitcoind-rpc');

var config = {
    protocol: 'http',
    user: 'bitcoin',
    pass: 'local321',
    host: '127.0.0.1',
    port: '18443',
};

var rpc = new RpcClient(config);

console.log("T")
sock.connect('tcp://127.0.0.1:29000');

sock.subscribe('rawtx')

sock.on('message', function(topic, message) {
  rpc.decodeRawTransaction(message.toString('hex'), function(err, resp) {
        console.log(JSON.stringify(resp, null, 4))
  })
})
2
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – Andrew Chow
    Apr 26, 2019 at 0:27
  • Added a short example.
    – Adys
    Apr 26, 2019 at 2:21
2

Notify when new transaction is arrive in a bitcoin address

To achive this what i have implemented is:

You need to have a crawler running on cronjob, which crawls each blocks(as well as mempool if you want to send 0th confirmation notification) and each transactions. While crawling transactions you need to check if its vout address i.e to_address of particular transaction is your address or not. If its your address you need to implement a notification service notifying to_address, value , txid and other required parameters.

You can use redis for faster comparision of transactions and addresses

rpc required :

getblockcount,getblockhash, getblock, getrawtransaction, getrawmempool
2

If the address doesn't have to be specific then you have a few options:

  • Use ZeroMQ for catching every single transaction that enters the mempool and check if it's relevant to your addresses.

  • Use walletnotify as a startup flag/config option to specify a command to execute with an option to pass the txid to the command. This will only catch the relevant transactions (so whenever one of your addresses is used as an input or output). However, it creates a new process every time that command gets executed, which, as far as I know, has a negative effect on the resources of your machine.

  • Read the txids from the stdout. This is the method I've been using. Things like new blocks and new transaction registration get logged in the stdout of the bitcoin core process. If you find a way to pipe that stdout somewhere and then extract txids or new block hashes there - you would, in essence, have the same relevant only notifications, but without spawning new processes.

7
  • Thanks a lot. Do you know any step-by-step guide to setup ZeroMQ for catching every single transaction enters the mempool? Jun 9, 2020 at 13:37
  • 1
    @AminShojaei what language are you using?
    – zabbir
    Jun 9, 2020 at 14:16
  • currently Php 7 Jun 9, 2020 at 16:52
  • I am using PHP7 Jun 10, 2020 at 5:00
  • 1
    Here's a NodeJS guide that worked for me: degreesofzero.com/article/…
    – zabbir
    Jun 10, 2020 at 18:16
1

Bitcoin Core's RPC mechanism is not a push interface and does not support notifications. Each RPC returns one JSON object, so to implement notification functionality using this, your application will frequently need to poll the bitcoin daemon for new information.

The RPC you probably want is listtransactions. This will return a list of recent transactions with their full details, which includes the pay-to address and the time it was added. Your application would simply filter out the transactions whose timestamp is earlier than the most recent notification, and create a notification for those whose timestamps are newer.

Not the answer you're looking for? Browse other questions tagged or ask your own question.