8

I want to access unspent data of a specific bitcoin address.

I am trying this command

bitcoin-cli -regtest listunspent "some bitcoin address"

But I am always getting an empty list. I am using local bitcoind server on windows 7.

What should I do or use any function for getting desired output ?

7 Answers 7

10

listunspent only displays information about addresses which are currently part of your wallet. Bitcoin Core does not maintain indexes of unspent outputs for addresses you do not own, and will simply return a blank set if you attempt to query for them.

1
  • Does txindex=1 help in any way for listunspent?
    – Jus12
    Commented Jun 16, 2022 at 19:46
3

In order to get the list unspent of a specific bitcoin address( not belongs to your wallet), you must first import the address to wallet using importaddress This RPC does not require the private key of that address. Note that this will cause the program to rescan the entire blockchain, which will take several minutes.

now you can use the listunspent call to get the UTXO.

Edit: use rescan : true if you are importing already existing address

6
  • I tried this but didnt work. I get an empty result array when I run listunspent rpc call Commented May 9, 2020 at 0:44
  • Do you imported the address?
    – Akshay Dev
    Commented May 10, 2020 at 2:02
  • Yes I did. What happens is when I importeadress I get this response { result: null, error: null, id: 'd542c95d-ad8f-4a8e-b92f-6a69fa051e9d' } And then when I try to listunsent I get { result: [], error: null, id: '460bdaa4-5209-4dc8-ba76-582e3e0cc0e4' } Commented May 10, 2020 at 6:07
  • hi @JosephAkayesi, The response is totally fine. you should enable rescan option if the address already have some unspents. eg:bitcoin-cli importaddress "myaddress" "testing" true. You can reffer here : bitcoin.org/en/developer-reference#importaddress
    – Akshay Dev
    Commented May 11, 2020 at 12:08
  • Wow. I read that rescans can take forever. For my use case I need to be able to read unspent values in less than at least 10 secs Commented May 12, 2020 at 13:10
2

As mentioned here, you can first get the addresses of an account using getaddressesbyaccount and then list all the unspent of those addresses using

bitcoin-cli listunspent 6 9999999 "[\"1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\",\"1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\"]"  

where 6 and 9999999 are the min and max confirmations

2
  • 3
    OP is asking about arbitrary addresses, not just those in his wallet. Commented Oct 31, 2017 at 6:40
  • oh.. my mistake :) hope this might help people who are looking to get unspent from the wallet addresses.
    – RealSteel
    Commented Nov 3, 2017 at 7:04
1

I have written a program that allows you to search for any address whether it belongs to your wallet or not, in Python3.

Here is the github link:

https://github.com/ORP967/Bitcoin_Core_RPC_par_address

Let me know if you guys have any improvements that can be made to it.

0

Assuming the addresses are in your wallet, you're looking for listreceivedbyaddress. That will give you back this:

Returns an array of objects containing:

  • "address" : receiving address
  • "account" : the account of the receiving address
  • "amount" : total amount received by the address
  • "confirmations" : number of confirmations of the most recent transaction included
  • "txids" : a list of transaction IDs that you can pass to gettransaction in order to see the full transaction.

(Source.)

11
  • Yup, But if i want to get unspents of an address which is not a part of my wallet ? than what function should i use ? @Nick Commented Apr 27, 2015 at 17:54
  • 2
    @HassanMehmood Doesn't exist. Use bitcoin-abe or electrum server or blockchain.info instead.
    – Nick ODell
    Commented Apr 27, 2015 at 18:22
  • Hey, from answers, I added one my multisig add using this command "addmultisigaddress". and sent some satoshis to this address. but I am still getting empty list after calling :listunspent" ??? Commented Apr 29, 2015 at 15:31
  • @HassanMehmood You need to rerun with rescan. bitcoin.stackexchange.com/questions/22199/…
    – Nick ODell
    Commented Apr 29, 2015 at 18:21
  • 1
    addmultisigaddress is not enough to make the wallet treat the address as its own; you also need to have all of the private keys. If you want to treat an address as yours regardless of keys, use importaddress. Commented Oct 31, 2017 at 6:39
0

Unspent data appears in Unspent List only after SIX confirmations.

Try this command,

bitcoin-cli -regtest listunspent "some bitcoin address" 0

It will show all the unspent transactions.

1
  • I am running the same command but getting empty list in response. I first generated and added a multisig address using "addultisigaddress" command and call listunspent. But in result i always get an empty list though I sent some satoshis to this address 2 times Commented Apr 29, 2015 at 17:40
0

Other options, beyond what Nick mentioned, are to either use the toshi.io API:

toshi.io - API - utxo's for address

Or run your own toshi node:

toshi.io

2
  • chain.com is also very good and easy to use! but i was trying not to use any 3rd party APIs. Commented Apr 29, 2015 at 7:57
  • @HassanMehmood if running the toshi node locally isn't something you want either (it consumes well over 200GB of space) then you could run bitcoin core with txindex enabled. You'd then have to parse the blockchain and build and keep up a database of utxo yourself. As others have pointed out, if you just want a bitcoin-cli argument for this, it doesn't exist. Commented Apr 30, 2015 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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