Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: linuxqq on June 23, 2020, 03:07:38 PM



Title: I want to use RPC to get all historical transactions of an address
Post by: linuxqq on June 23, 2020, 03:07:38 PM
I want to use RPC to get all historical transactions of an address,I have synchronized the full node on my computer. Below is the configuration of my bitcoin.conf

Code:
blockfilterindex=1
datadir=/opt/bitcoin/bitcoin-data
dbcache=10240
txindex=1
reindex=1
rpcuser=xxx
rpcpassword=xxx
daemon=1
server=1
rest=1
rpcbind=0.0.0.0:8332
rpcallowip=0.0.0.0/0
deprecatedrpc=accounts

But the result I return using listtransactions is empty
Code:
root@ubuntu:/opt/bitcoin/bitcoin-data# bitcoin-cli listtransactions "1L671pxzdY9dzEayZ9yEfUVWAoGsq99PoC"
[]

I don’t know what I did wrong, I just want to synchronize a full node locally, can query all historical transaction records of any specified address, thank you for your help



Title: Re: I want to use RPC to get all historical transactions of an address
Post by: BrewMaster on June 23, 2020, 03:52:44 PM
can query all historical transaction records of any specified address, thank you for your help

that is not possible with the way a full node (like bitcoin core)stores the blockchain because the blocks and their transactions are not sorted based on addresses so that you could easily search for address historical transactions.

you'll have to either rescan the entire blockchain for each address, which takes a lot of time or use another tool to index the blockchain based on addresses like what block explorers do then search it.


Title: Re: I want to use RPC to get all historical transactions of an address
Post by: linuxqq on June 24, 2020, 01:16:27 AM
So do I still need my own database to store transaction records at these addresses?


Title: Re: I want to use RPC to get all historical transactions of an address
Post by: DaveF on June 24, 2020, 01:20:35 AM
So do I still need my own database to store transaction records at these addresses?
Yes.
There are some long and complicated ways around it, but none are simple.
If you want to get the information without going to a public explorer, there are many open source ones that you can use.

https://github.com/iquidus/explorer
https://github.com/bitpay/bitcore

-Dave


Title: Re: I want to use RPC to get all historical transactions of an address
Post by: domob on June 24, 2020, 05:20:31 AM
As others have already pointed out, this is not possible (at least not easily) with Bitcoin Core alone.  As an alternative to block explorers already mentioned, you can also run ElectrumX (https://github.com/kyuupichan/electrumx) to generate and maintain a database indexed by address.  Once synced up, ElectrumX allows you to query exactly for the data you want.


Title: Re: I want to use RPC to get all historical transactions of an address
Post by: linuxqq on July 09, 2020, 03:57:37 AM
Thank you very much for your reply. Maybe I don’t have a special understanding of the principles of Bitcoin, but I’m working hard to learn. I currently read the electrumx rosksdb directly. It seems that electrumx stores scripthash, but I want to get all the wallet addresses, a lot of BTC explorer How did they get the wallet address? electrumx's database does not store scriptPubKey