7

does bitcoin-cli have any functionality to get all tx hashes for a given address (ie the txs that either send or receive funds from the given address). listtransactions sounds like it should do what i want, but when i run it like so then i get no results:

# pick a random address to watch from blockchain.info:
$ addr=1GkktBuJ6Pr51WEJe5ZzyNvMYaMDFjwyDk
# create a watch-only account for this address, with the account name
# being the address itself, for convenience:
$ time bitcoin-cli importaddress $addr "$addr" true
real    41m59.505s
user    0m0.004s
sys 0m0.004s
$ bitcoin-cli listtransactions "$addr" 100 0 true
[
]
$ bitcoin-cli getinfo
{
    "version" : 100200,
    "protocolversion" : 70002,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 384809,
    "timeoffset" : 0,
    "connections" : 8,
    "proxy" : "",
    "difficulty" : 65848255179.70261383,
    "testnet" : false,
    "keypoololdest" : 1381701523,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "relayfee" : 0.00001000,
    "errors" : ""
}

as you can see, it takes 42 minutes to scan the blockchain for this watch-only address, so its not something i want to do often. and its only producing an empty list, whereas blockchain.info shows there are 6 transactions.

why is this not working? is this not the intended functionality of bitcoin-cli listtransactions?

update

listtransactions is supposed to display transactions from watch-only addresses:

$ bitcoin-cli help listtransactions
listtransactions ( "account" count from includeWatchonly)

Returns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.

Arguments:
1. "account"    (string, optional) The account name. If not included, it will list all transactions for all accounts.
                                     If "" is set, it will list transactions for the default account.
2. count          (numeric, optional, default=10) The number of transactions to return
3. from           (numeric, optional, default=0) The number of transactions to skip
4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')
...
...
...
  • 1
    I think you need to enable the -txindex option for this. When you first enable this bitcoind will have to re-process the entire transaction history to fill this new transaction index which will take a while. It will also cost you more disk space. ~30 GB extra I think. – Jannes Nov 23 '15 at 3:08
  • @Jannes i compiled it from source, but i can't remember if i had this flag enabled. i know other watch-only functionality is working though. do you know if there is there any way of checking if i have this setting enabled without recompiling? – mulllhausen Nov 23 '15 at 3:39
  • It's not a compile time setting, it's a runtime argument. txindex 1 in the conf file. But it looks like I was wrong and you actually don't need to do that. github.com/bitcoin/bitcoin/pull/4045 (they mention listtransactions ignores watch only on purpose there.) – Jannes Nov 23 '15 at 9:52
  • @Jannes but the final argument of listtransactions is includeWatchonly. please see my update in the question. – mulllhausen Nov 23 '15 at 11:48
  • Are you sure the transactions happened AFTER you did importaddress ? I'm pretty sure it won't search the whole blockchain for older transactions. (It might if you had txindex=1, but I'm not sure if that affects this.) – Jannes Nov 23 '15 at 12:40
3

Seeing as this question remains unanswered after a few months...

You will need to enable txindex = 1 in your bitcoin.conf per @Jannes' suggestion. If you want to scan your downloaded blockchain for another wallet's address transaction history, then you have to build the entire blockchain index on your machine.

Whether it's a watch-only address or not should be irrelevant.

What are pros and cons of txindex option?

Get non-wallet transactions using bitcoin rpc (gettransaction)

UPDATE

I think I may have solved your problem

This is my Bitcoin info

$ bitcoin-cli getinfo
{
    "version" : 110200,
    "protocolversion" : 70002,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 353776,
    "timeoffset" : -1,
    "connections" : 55,
    "proxy" : "",
    "difficulty" : 47610564513.47126007,
    "testnet" : false,
    "keypoololdest" : 1449210293,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "relayfee" : 0.00005000,
    "errors" : ""
}

My blockchain isn't quite as up-to-date as yours, so I gathered this transaction (within block 353776) and used the Bitcoin address of 1CTVqQSSVTjun32gRxmhJHhVYzzXpR894z from that transaction for my example.

# Import address WITHOUT rescan; we'll do this later
bitcoin-cli importaddress 1CTVqQSSVTjun32gRxmhJHhVYzzXpR894z "Index Test" false

# Stop Bitcoin
$ bitcoin-cli stop

# Verify Bitcoin is stopped, then run:
$ bitcoind -rescan

# Wait for rescan... mine took 15-20 minutes

# Once 'bitcoin-cli getinfo' returns valid info, run:
$ bitcoin-cli listtransactions "Index Test" 10 0 true

# Result:

[
    {
        "involvesWatchonly" : true,
        "account" : "Index Test",
        "address" : "1CTVqQSSVTjun32gRxmhJHhVYzzXpR894z",
        "category" : "receive",
        "amount" : 3.50000000,
        "vout" : 0,
        "confirmations" : 22539,
        "blockhash" : "00000000000000000548d8ef9a7d14c75b7b18ae5b792d520f44cc5ddd25adfe",
        "blockindex" : 536,
        "blocktime" : 1416848183,
        "txid" : "1db7b0703f441d4cea63a298131f8e766b557329f44c30898847d0fc23573606",
        "walletconflicts" : [
        ],
        "time" : 1452652576,
        "timereceived" : 1453438387
    },
    {
        "involvesWatchonly" : true,
        "account" : "Index Test",
        "address" : "1CTVqQSSVTjun32gRxmhJHhVYzzXpR894z",
        "category" : "receive",
        "amount" : 1.89990000,
        "vout" : 1,
        "confirmations" : 19031,
        "blockhash" : "0000000000000000134345f88fb68550d2102d392be6e1635eaa6fb50c37a2cc",
        "blockindex" : 15,
        "blocktime" : 1418994502,
        "txid" : "4cc761b286c23dab5dd07c260726d79e4baee88778a402e36c82a6b9e6ac757f",
        "walletconflicts" : [
        ],
        "time" : 1452652576,
        "timereceived" : 1453438430
    },
    ...
    snip
    ...
    {
        "involvesWatchonly" : true,
        "account" : "Index Test",
        "address" : "1CTVqQSSVTjun32gRxmhJHhVYzzXpR894z",
        "category" : "receive",
        "amount" : 13.63000000,
        "vout" : 0,
        "confirmations" : 211,
        "blockhash" : "0000000000000000021df02390f30985f34d871e4cc93c4e349cd3b23574bf76",
        "blockindex" : 1,
        "blocktime" : 1430041109,
        "txid" : "64540e42ec96118d11168d954641dd5390f4a46ba795c7b7588d38141e66117a",
        "walletconflicts" : [
        ],
        "time" : 1452652576,
        "timereceived" : 1453438694
    }
]

As you can see, the last transaction to show in the output is the one I grabbed from block 353776, with all of the correct details as displayed on blockchain.info, indicating a successful transaction listing for the imported address (account containing the address, actually).

As for why your rescan didn't work when you initially imported the address, I can't really say. Perhaps a more seasoned Bitcoin user could shed some light on that.

At this point, I recommend you stop your Bitcoin daemon and run bitcoind -rescan and wait for it to do its magic. Afterwards try your listtransactions again. I'm interested in finding out if it works for you.

Keep in mind that attempting to import a Bitcoin address that already exists within your wallet will not initiate a rescan, even if specified to do so on the command line. --- https://bitcoin.org/en/developer-reference#importaddress

  • txindex=1 is already the case for me. for example bitcoin-cli getrawtransaction 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098 works fine, though i obviously this transaction is not relevant to my personal wallet. – mulllhausen Jan 21 '16 at 5:54
  • also please see the discussion below the question. this solution has already been proposed and did not work. – mulllhausen Jan 21 '16 at 6:05
  • My apologies, I understand your dilemma now. When you run bitcoin-cli listaccounts, is the address you imported displayed in the output? – maff1989 Jan 21 '16 at 14:44
  • no worries. no it is not. if you could try doing the import and letting me know if you see it in yours that would be very helpful. – mulllhausen Jan 22 '16 at 1:36
  • I have provided an update to my answer. Please let me know if that helps in resolving your issue. – maff1989 Jan 22 '16 at 20:07

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.