0

I'm running bitcoind bitcoind -regtest and want to send BTC to bcrt1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvst4ql45 segwit address.

Why listunspent returns empty list after sending somebtc to segwit address?

Check sender has enough bitcoin

➜  bin ./bitcoin-cli -regtest getbalance
20.17930334

Send BTC

➜  bin ./bitcoin-cli -regtest sendtoaddress bcrt1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvst4ql45 15.1
eb5e0047c3c37ad6f020e34febb52da276817196063ba2efc5860aa59f92cff4

Get TX

➜  bin ./bitcoin-cli -regtest gettransaction eb5e0047c3c37ad6f020e34febb52da276817196063ba2efc5860aa59f92cff4
{
  "amount": -15.10000000,
  "fee": -0.00044248,
  "confirmations": 101,
  "blockhash": "17e269809ab17fb41813f401fc8342a036c18509eb33504e8da87c82c9759e4f",
  "blockheight": 2858,
  "blockindex": 2,
  "blocktime": 1681583966,
  "txid": "eb5e0047c3c37ad6f020e34febb52da276817196063ba2efc5860aa59f92cff4",
  "walletconflicts": [
  ],
  "time": 1681583928,
  "timereceived": 1681583928,
  "bip125-replaceable": "no",
  "details": [
    {
      "address": "bcrt1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvst4ql45",
      "category": "send",
      "amount": -15.10000000,
      "vout": 1,
      "fee": -0.00044248,
      "abandoned": false
    }
  ],
  "hex": "020000000001fd8c020628c3940819bf09b7d2383de51bf6dd8b03fb0ad58fdfc98d85bdf34aec96470000000000feffffff85abf943b973ab67bb3fc88ab922c36b3dd2c2ad61d84d5

Generate blocks for confirmation

➜  bin ./bitcoin-cli -regtest -generate 101                                                  

{
  "address": "bcrt1qkg54v3hqj4gpl9k0x8evlft3df2cuxetrr6e8l",
....

Get UTXOs for the address

➜  bin ./bitcoin-cli -regtest listunspent 0 999999 "[\"bcrt1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvst4ql45\"]"

[
]

Why listunspent returns empty list, even. after transmission.

Best

4
  • 1
    Is bcrt1qxhx5gq5gwaju2lh0pxnp7qpn4685cwvst4ql45 your address (e.g what does getaddressinfo say about it?)? listunspent is a wallet RPC, it queries your own wallet for UTXOs. If you want non-wallet UTXO lookup, use gettxout (though that works by txid:idx, not by address). Commented Apr 15, 2023 at 19:13
  • Thank you! Missed that nuance. How can I get UTXO's of an address to build a tx?
    – att
    Commented Apr 15, 2023 at 19:29
  • Import them in the wallet first, so it tracks them for you. Then listunspent and even higher-level transaction building RPCs will work just fine. Bitcoin Core has no functionality for indexing transactions or UTXOs by address, though you can use scantxoutset which will just search through the entire UTXO set for entries matching a given output descriptor (which may include an address). Commented Apr 15, 2023 at 19:33
  • I've been struggling to get UTXOs from the RPC. So that's the reason most examples use external APIs to get UTXOs. Thanks
    – att
    Commented Apr 15, 2023 at 20:02

0

Your Answer

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