getTransaction requires txindex
oleksandr-shubin opened this issue · 4 comments
I am using bitcoin-rpc-client in conjunction with walletnotify to get transaction data upon first confirmation. The problem is that getTransaction
method returns Invalid Tx
because of the following error under the hood:
No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.
I can set txindex
, but it's redundant for me, as I am interested only in my wallet transactions, moreover AFAIU it will add some performance overhead.
I've found the source of the problem, but still can't understand the solution. Both getTransaction
and getRawTransaction
methods now do getrawtransaction
under the hood which is inconvenient when one works with his own wallet transactions only
Have you tried using listUnspent? That also goes over transactions in the mempool. Only difference is it works with utxos instead of transactions.
See discussion here about why txindex
is needed for getTransaction
.
If you're working and only interested in your own wallet's transactions, have a look at listUnspent which lists the utxos of the addresses in your wallet. This does not need txindex
. You could call it for example using blocknotify, which indicates to you that 1) there are potentially new wallet transactions, and 2) relevant mempool transactions may have gotten 1 confirmation.