8
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
getBlockcommand to get all transaction hash - Run a for loop for each transaction hash to run
getTransactioncommand - 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?
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 – 2018-10-05T14:47:35.570
4fwiw, the reason
walletnotifyexecutes 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 withblocksonly=1which will disable mempool and causewalletnotifyto execute once (when a tx is confirmed in a new block) – arubi – 2018-12-16T22:07:37.277