<p>I see a solution using <a href="https://github.com/bitcoin/bitcoin/blob/master/doc/zmq.md" rel="nofollow noreferrer">ZMQ</a>.</p>

<p><a href="https://github.com/bitcoin/bitcoin/blob/dac2caa371a1c65faf34966c85dbafc30a0c640a/contrib/zmq/zmq_sub.py" rel="nofollow noreferrer">An example</a> of using it is also available on Python.</p>

<p>By enabling ZMQ you can process network updates (blocks, new transactions) and select most relevant events accordingly. Also, some libraries to deserialize bitcoin blocks and transactions could be useful. If you work with Python, you can use python-bitcoinlib.</p>

CC BY-SA 4.0
2020-02-06T10:20:00.167Z
2020-02-06T10:20:00.167Z
Ilya Evdokimov
<p><code>walletnotify</code> executes once per every unconfirmed transaction creation (incoming/outgoing) and once more once the transaction is mined into a block (gets it's first confirmation).</p>

<p>I am not sure what are you developing, but as far as I see it both notifications are essential:
The first one to let the customer know that his transaction had been recorded, and the second to know that the value was indeed remitted, with enough fee, and will not be double spent.</p>

<p>For more info please review the official documentation.
<a href="https://en.bitcoin.it/wiki/Running_Bitcoin" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Running_Bitcoin</a></p>

CC BY-SA 4.0
2018-12-30T04:06:40.050Z
2018-12-30T04:06:40.050Z
Oleg Belousov
<p>Not sure if this will be efficient enough for you, but when walletnotify is called it can pass along the txid it was called with. Then whatever program is executed, from walletnotify can do something like a decoderawtransaction using that txid and see if the blockHash field is filled in, and confirmations>0.</p>

<p>You can also use some intermediary program to prevent the primary program from being called twice. For example in bitcoin.conf have walletnotify call to something like 'checkconfirmed.py' . checkonfirmed.py can do the decoderawtransaction opreration described above, and only if confirmed will it call out to "finalprogram.py".</p>

CC BY-SA 4.0
2018-12-29T00:05:35.007Z
2018-12-29T00:05:35.007Z
Fraggle
<p>How can I get Bitcoin receive notifications with Bitcoin Core. I have tried the <code>walletnotify</code> and <code>blocknotify</code> options. <code>walletnotify</code> is fired two times when I send or receive bitcoins. And with <code>blocknotify</code> I have to perform below task to detect which account of the wallet has received bitcoin.</p>

<ul>
<li>Run <code>getBlock</code> command to get all transaction hash</li>
<li>Run a for loop for each transaction hash to run <code>getTransaction</code> command</li>
<li>If transaction hash belong to my wallet account, I save the receive transaction in my database. </li>
</ul>

<p>Using <code>blocknotify</code> seems to be inefficient as it involves lots of RPC calls per transaction.</p>

<p><code>walletnofity</code> executes twice for bitcoin send and receive.</p>

<p>I have also tried <code>ZMQ</code> but I got a response which is difficult to convert into desirable format.</p>

<p>So could anybody suggest some efficient way to get a bitcoin receive notification upon first confirmation?</p>

CC BY-SA 4.0
2018-12-16T22:07:37.277Z
fwiw, the reason `walletnotify` executes twice is because the first time is for when a tx enters your mempool, and the second time is for when the tx is confirmed.  You should care about the second one if it's an incoming payment.  Also you can run with `blocksonly=1` which will disable mempool and cause `walletnotify` to execute once (when a tx is confirmed in a new block)
arubi
CC BY-SA 4.0
2018-10-05T14:47:35.570Z
Since your current problem is inefficiency, i suggest writing to a sub/pub queue only onetime per new block or maintaining a database with receive indexes and query the DB (don't forget to manage a reorganization case)
youssef
<bitcoin-core><bitcoind><receiving>
How to get notification on bitcoin receive with bitcoin core
Ajit Soman
# How to get notification on bitcoin receive with bitcoin core

(Asked by: username_0 on 2017-12-16)

How can I get Bitcoin receive notifications with Bitcoin Core. I have tried the `walletnotify` and `blocknotify` options. `walletnotify` is fired two times when I send or receive bitcoins. And with `blocknotify` I have to perform below task to detect which account of the wallet has received bitcoin.

* Run `getBlock` command to get all transaction hash
* Run a for loop for each transaction hash to run `getTransaction` command
* If transaction hash belong to my wallet account, I save the receive transaction in my database.

Using `blocknotify` seems to be inefficient as it involves lots of RPC calls per transaction.

`walletnofity` executes twice for bitcoin send and receive.

I have also tried `ZMQ` but I got a response which is difficult to convert into desirable format.

So could anybody suggest some efficient way to get a bitcoin receive notification upon first confirmation?

**Tags:** bitcoin-core, bitcoind, receiving

> **Comments:**
> **username_2**: Since your current problem is inefficiency, i suggest writing to a sub/pub queue only onetime per new block or maintaining a database with receive indexes and query the DB (don't forget to manage a reorganization case)  
> **username_1**: fwiw, the reason `walletnotify` executes twice is because the first time is for when a tx enters your mempool, and the second time is for when the tx is confirmed.  You should care about the second one if it's an incoming payment.  Also you can run with `blocksonly=1` which will disable mempool and cause `walletnotify` to execute once (when a tx is confirmed in a new block)  

---

## 3 answers

### Answer by username_3 on 2020-02-06. Score: 1

I see a solution using [ZMQ](https://github.com/bitcoin/bitcoin/blob/master/doc/zmq.md).

[An example](https://github.com/bitcoin/bitcoin/blob/dac2caa371a1c65faf34966c85dbafc30a0c640a/contrib/zmq/zmq_sub.py) of using it is also available on Python.

By enabling ZMQ you can process network updates (blocks, new transactions) and select most relevant events accordingly. Also, some libraries to deserialize bitcoin blocks and transactions could be useful. If you work with Python, you can use python-bitcoinlib.


---

### Answer by username_4 on 2018-12-30. Score: 1

`walletnotify` executes once per every unconfirmed transaction creation (incoming/outgoing) and once more once the transaction is mined into a block (gets it's first confirmation).

I am not sure what are you developing, but as far as I see it both notifications are essential:
The first one to let the customer know that his transaction had been recorded, and the second to know that the value was indeed remitted, with enough fee, and will not be double spent.

For more info please review the official documentation.
<https://en.bitcoin.it/wiki/Running_Bitcoin>


---

### Answer by username_5 on 2018-12-29. Score: 0

Not sure if this will be efficient enough for you, but when walletnotify is called it can pass along the txid it was called with. Then whatever program is executed, from walletnotify can do something like a decoderawtransaction using that txid and see if the blockHash field is filled in, and confirmations>0.

You can also use some intermediary program to prevent the primary program from being called twice. For example in bitcoin.conf have walletnotify call to something like 'checkconfirmed.py' . checkonfirmed.py can do the decoderawtransaction opreration described above, and only if confirmed will it call out to "finalprogram.py".


---

