1

How to use python rpc bitcoin to get the historical transaction record of a wallet address?My computer has synchronized all btc blocks, and txindex=1 has been configured. I want to try to get all the historical transaction records of a wallet address. Do I still need to create a mysql or redis cache? Below is my configuration

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

I just want to input an address and connect to the local BITCOIN RPC to query all historical transaction records of a specific address

An empty message was returned

root@ubuntu:~# bitcoin-cli listtransactions  "3Fr1mGhnPAQ9YDf1dzg4B47PkX5TuvFtYv"
[
]
  • Bitcoin-core does not keep an index of address balances or histories. You will need to find/write some additional code in order to use it in this way. – chytrik Jun 22 at 20:55
1

As @hamita pointed out you need to set server=1 in your bitcoin.conf file then you can use python-bitcoinrpc library to communicate with your bitcoin node.

Here's a short script to get all transactions of an address:

from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from pprint import pprint

# rpc_user and rpc_password are set in the bitcoin.conf file
rpc_user = "<from bitcoin.conf>"
rpc_pass = "<from bitcoin.conf>"
rpc_host = "<ip address of your bitcoind>" # if running locally then 127.0.0.1
rpc_client = AuthServiceProxy(f"http://{rpc_user}:{rpc_pass}@{rpc_host}:8332", timeout=240)


track_address = "<your address>"
tx_list = rpc_client.listtransactions()

address_tx_list = []
for tx in tx_list:
    if tx['address'] == track_address:
        address_tx_list.append(tx)

pprint(address_tx_list)

I'm also writing the chapter Accessing Bitcoind with Python if you want to know more. NOTE: It is a work in progress.

EDIT: Added server=1 for completeness.

| improve this answer | |
  • I just want to input an address and connect to the local BITCOIN RPC to query all historical transaction records of a specific address,I can't query all historical transaction records by trying this code, is there any good idea? thank – user51679 Jun 23 at 2:46
  • An empty message was returned root@ubuntu:~# bitcoin-cli listtransactions "3Fr1mGhnPAQ9YDf1dzg4B47PkX5TuvFtYv" [ ] – user51679 Jun 23 at 10:45
  • That is because that address is not being tracked by your node as it wasn't generated by it nor it isn't watching the wallet that generated that address. If you want to be able to track each and every address then you should use something like esplora which is what blockstream.info backed is. – jodobear Jun 25 at 0:01
1

To communicate with your bitcoin core, you must change your bitcoin.conf and set

server=1

Then connect to your bitcoin core with "http://user:password@127.0.0.1:8332"

| improve this answer | |
  • This page will help you to config your node. jlopp.github.io/bitcoin-core-config-generator – mengeroshi Jun 22 at 21:59
  • I have configured this parameter server=1, but executing bitcoin-cli listtransactions 1JXKXFuB4HZf18JnpKADe2R3J8taoCcQEE still returns empty – user51679 Jun 23 at 14:32
  • @user51679 Edit those in your conf file rpcallowip=127.0.0.1 rpcport=8332 – Hamita Jun 23 at 14:40
  • The address I monitor is any address, is there any difference between this and 127.0.0.1 monitoring? Affect the query? – user51679 Jun 23 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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