dgarage / NBXplorer

NBitcoin Explorer
MIT License
320 stars 213 forks source link

How to use API for get current balance #309

Closed VeilleurTrytoFix closed 3 years ago

VeilleurTrytoFix commented 3 years ago

hi, i dont understand how to get the current balance over the API:

Example random address : 17XiVVooLcdCUCMf9s4t4jTExacxwFS5uh Format : BASE58 (P2PKH) ----> https://www.blockchain.com/btc/address/17XiVVooLcdCUCMf9s4t4jTExacxwFS5uh

if i use API docs i got :

Address type Format P2WPKH xpub1 P2SH-P2WPKH xpub1-[p2sh] P2PKH xpub-[legacy] Multi-sig P2WSH 2-of-xpub1-xpub2 Multi-sig P2SH-P2WSH 2-of-xpub1-xpub2-[p2sh] Multi-sig P2SH 2-of-xpub1-xpub2-[legacy]

http://127.0.0.1:24444/v1/cryptos/btc/derivations/xpub-[legacy]/17XiVVooLcdCUCMf9s4t4jTExacxwFS5uh/balance

i got 404Not

http://127.0.0.1:24444/v1/cryptos/btc/addresses/17XiVVooLcdCUCMf9s4t4jTExacxwFS5uh/balance i got

{ "unconfirmed": 0, "confirmed": 0, "total": 0 }

but on blockchain.info they said :

Final Balance 0.01210626 BTC

why i got 0 ?

everything works fine because with :

http://127.0.0.1:24444/v1/cryptos/btc/status

{ "bitcoinStatus": { "blocks": 676697, "headers": 676697, "verificationProgress": 0.999999514559769, "isSynched": true, "incrementalRelayFee": 1.0, "minRelayTxFee": 1.0, "externalAddresses": [], "capabilities": { "canScanTxoutSet": true, "canSupportSegwit": true, "canSupportTransactionCheck": true } }, "repositoryPingTime": 1.45E-05, "isFullySynched": true, "chainHeight": 676697, "syncHeight": 676697, "instanceName": "", "networkType": "Mainnet", "cryptoCode": "BTC", "supportedCryptoCodes": [ "BTC" ], "version": "2.1.49.0" }

what im doing wrong for get balance addr over api?

thanks

NicolasDorier commented 3 years ago

NBXplorer is not a full block explorer.

You need to track an address first, then after tracked it will detected payment to and from it. (but nothing before it has been tracked)

This design is intentional, making a full block explorer requires lot's of resources (storage/cpu/sync time) NBXplorer, by tracking only when asked to do so, it almost take no resource.

VeilleurTrytoFix commented 3 years ago

ok ty