Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: copyleft on August 19, 2019, 06:09:30 PM



Title: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: copyleft on August 19, 2019, 06:09:30 PM
I'm getting Cloudflare blocked by Blockcypher and chain.so's APIs.

I'm told there's no performant (milliseconds) method to retrieve address balance for an address in one's bitcoin core wallet, it'd take minutes. Is bitcore's node tools a viable option for balance retrieval, getting unspent tx's, and broadcasting?

Any any insight for similar support tools for litecoin?

bonus question: referrals to any non-cloudflare baring API's that hold BTC and/or LTC blockchain data are appreciated


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: achow101 on August 19, 2019, 08:58:55 PM
If you want just the UTXO(s) and don't care about an address's transaction history, you can use Bitcoin Core's scantxoutset command (available since 0.17.0) to scan just the UTXO set and retrieve the UTXOs for a given address or script. The command will also return you the total value of the UTXOs that it found for the address or script.

Once you have the UTXOs, you can get the full transactions if you have the transaction index enabled.


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: copyleft on August 20, 2019, 04:28:54 PM
If you want just the UTXO(s) and don't care about an address's transaction history, you can use Bitcoin Core's scantxoutset command (available since 0.17.0) to scan just the UTXO set and retrieve the UTXOs for a given address or script. The command will also return you the total value of the UTXOs that it found for the address or script.

Once you have the UTXOs, you can get the full transactions if you have the transaction index enabled.


Thanks for the reply. I got my bitcoind server running in testnet on localhost:18332.

I'm figuring it out, but what would the url structure look like for the POST request to the RPC server for scantxoutset?'


Edit: got it, read the API reference. You POST localhost:18332 with { id: 'jsonrpc', method: 'scantxoutset', ....relevant_args } and basic auth with your rpcuser and rpc password from your bitcoin.conf. For anyone who ends up here.


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: copyleft on August 20, 2019, 05:36:03 PM
Okay, having another issue actually.

Continually getting 500 errors when POSTing with method scantxoutset:



method: 'scantxoutset',
id: 'jsonrpc',
action: "start",
scanobjects: [
        "addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)",
        {
          "desc": "addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)",
          "range": 1000,
        }
    ]


also tried :     [
        {
          "desc": "addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)",
          "range": 1000,
        }
    ]

and simply:

['addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)']
500 Errror and gives me the same text from the link you sent.

I'll keep testing but, I'd love if someone can point out the error


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: achow101 on August 20, 2019, 05:56:25 PM
Okay, having another issue actually.

Continually getting 500 errors when POSTing with method scantxoutset:



method: 'scantxoutset',
id: 'jsonrpc',
action: "start",
scanobjects: [
        "addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)",
        {
          "desc": "addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)",
          "range": 1000,
        }
    ]


also tried :     [
        {
          "desc": "addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)",
          "range": 1000,
        }
    ]

500 Errror and gives me the same text from the link you sent.

I'll keep testing but, I'd love if someone can point out the error
You've specified an address descriptor with a range, which is not valid.

Just do
Code:
["addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)"]


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: copyleft on August 20, 2019, 07:12:31 PM
Code:
bitcoin-cli scantxoutset start  "[\"addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)\"]"


That works (only when I enter it as a text JSON array) but I'm having issues with getting the JSON RPC request to succeed"

BitcoinRPC class from here (ruby): https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)

btc = BitcoinRPC.new("http://rpcuser:rpcpassword@127.0.0.1:18332")

btc.getaddress    => "2NCixvAERq3eDt31jM7eYATGiHdTEcizQkj"     THIS WORKS

arguments =  { action: 'start', scanobjects: ["addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)"] }.to_json

btc.scantxoutset(arguments)  => BitcoinRPC::JSONRPCError: {"code"=>-8, "message"=>"Invalid command"}   Doesn't work...


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: achow101 on August 20, 2019, 07:21:57 PM
btc.scantxoutset(arguments)  => BitcoinRPC::JSONRPCError: {"code"=>-8, "message"=>"Invalid command"}   Doesn't work...
That error means that the scantxoutset command doesn't exist in your version of Bitcoin Core. What version are you using?


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: copyleft on August 20, 2019, 07:43:52 PM
Code:
$ bitcoin-cli --version
Bitcoin Core RPC client version v0.18.0.0-g2472733a24a9364e4c6233ccd04166a26a68cc65

I'm using bitcoin-cli through Ubuntu Linux subsystem and running bitcoin daemon through cmd.exe on Windows (can't seem to find the windows equivalent for bitcoin-cli for windows?)

I figure it will interface with the server running through main Windows, since it's on the same ports. I have 0.18.0 of Bitcoin Core on Windows.



Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: achow101 on August 20, 2019, 08:10:43 PM
It turns out Invalid command is not the error for a non-existent RPC method. It's actually saying that scantxoutset does not recognize the action that was given.

This appears to just be a question of how to pass in these parameters into the Ruby code. Unfortunately I am not very familiar with Ruby.

Could you try this line for setting arguments:
Code:
arguments =  { 'action' => 'start', 'scanobjects' => [ 'addr(mfskMRWntcPYdDgTJRJdwzdKiiHJikfvH4)' ]  }


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: darkv0rt3x on September 19, 2020, 05:59:12 PM
Hello

Sorry to use the same thread but it's about the same command in a different context.
I'm trying to use the command scantxoutset but without examples it's a bit harder to grasp it's usage.
I'm using Bitcoin Core 0.20.1 (full node) under Debian Buster.

I want to check the  utxos in a given address. I tried the following:

Code:
./bitcoin-cli scantxoutset start "[\"addr(address_here)\"]"

but either the command is taking too long to return any output or I'm misusing.

Any help?


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: HCP on September 19, 2020, 09:35:31 PM
It can take a number of seconds/minutes to return a response to scantxoutset...

To see the percentage progress of the "current" scan, you can use the following command from another shell:
Code:
./bitcoin-cli scantxoutset status

For example, the output:
Code:
{
  "progress": 13
}
shows us that the scan is 13% complete.


Title: Re: Check address balance, get unspent TX, and broadcast thru bitcoind or bitcore
Post by: darkv0rt3x on September 20, 2020, 03:25:15 PM
It can take a number of seconds/minutes to return a response to scantxoutset...

To see the percentage progress of the "current" scan, you can use the following command from another shell:
Code:
./bitcoin-cli scantxoutset status

For example, the output:
Code:
{
  "progress": 13
}
shows us that the scan is 13% complete.

Yes, yesterday I replied here after I noticed that. It worked like I issued thhe command, but my message was deleted.

Thank you anyways.