Author

Topic: Architecture and code for retrieving Wallet Address balance and transactions (Read 263 times)

legendary
Activity: 3472
Merit: 10611
how do I get going about this? in a "for dummies" series, how would you start this?

I mean, lets assume I have Visual Studio Code (as my IDE), which library should I download, use,,, is there any "example" as step by step?

i think since you want to use the protocol then the best reference is the main client that is already using the protocol (and has basically defined it), meaning Electrum. if you know python then your work is cut out for you since you can just look at its source code here: https://github.com/spesmilo/electrum
newbie
Activity: 17
Merit: 6
it depends on what you you want to do with all that. you may be better off installing a decent wallet and use that. wallets usually show your transaction history with all the additional info such as fees.


Thank you for your suggestion, but I need it programmatically on a server and the address might as well change, therefore the info from a wallet cannot work...

other wise you have to read the documentation and learn how to use the command line or JSON RPC. i suppose you can do it both with your bitcoin core full node and also with using remote Electrum nodes.
core: https://bitcoin.org/en/developer-reference#bitcoin-core-apis
electrum: https://electrumx.readthedocs.io/en/latest/

in bitcoin core listaddressgroupings and listtransactions commands return list of addresses and transactions.
in electrum blockchain.scripthash.get_balance and blockchain.scripthash.get_history return address balance and transaction history (only hashes you have to get the tx separately).

this si exactly what I would need, and at the same time I would prefer not to host a full node, therefore I like the idea of connecting to an available ElectrumX node...

now the challenge starts (for me, because I am a newbie Smiley)

how do I get going about this? in a "for dummies" series, how would you start this?

I mean, lets assume I have Visual Studio Code (as my IDE), which library should I download, use,,, is there any "example" as step by step?

Thank you heaps!
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
A way to programmatically see the transactions that happened in a wallet would be useful to me too because I plan to write some backend code that gets an event when someone makes a transaction to one of my wallet addressees  i.e. when someone pays me. So there would need to be a way for the code to find out when a transaction to my wallet addresses has enough confirmations to be considered paid. I'm open for suggestions for python libraries but any language would be alright too.
jr. member
Activity: 39
Merit: 6
Hello,

I am trying to build a simple app that retrieve Bitcoin balance, transactions and fee for a given Public Wallet Address...

for example, if we get the following Address: 1GB2CgZ9a4yXFaaN2YfmTKuhZbomkpUfbH btc.com api woudl give me exactly what I need with two API calls:

- Balance: https://chain.api.btc.com/v3/address/1GB2CgZ9a4yXFaaN2YfmTKuhZbomkpUfbH
- Transactions/fees: https://chain.api.btc.com/v3/address/1GB2CgZ9a4yXFaaN2YfmTKuhZbomkpUfbH/tx

Because these services changes and often have some limitations (e.g. # of API calls per second/per IP), I would prefer to build the same results on my infrastructure...

my next steps are:

1) install a bitcoin Node in my infrastructure (do I need a full node? I would prefer to have something "lighter" to save data storage and bandwidth)....

2) create a code that interact with the node and retrieve what I need...

Because I am a newbie, is there anyone who can address me how to achieve my end goal? Smiley

sorry, I am not sure where to start....

Thank you all!

I'd recommend using one of the many ElectrumX servers that are out there, if your goal is to build such an app. If you have the Electrum bitcoin wallet installed you can grab a live server by clicking Tools -> Network then go to the server tab where you'll see a bunch of servers, choose one from there.

You can connect to the server using something like:
Code:
nc electrumx.kenrufe.com 50001

Then issue commands by copy-pasting them into your terminal, eg:

Subscribe to new blocks:
Code:
{"id": 1, "jsonrpc":"2.0", "method": "blockchain.headers.subscribe"}

Get the balance of an address:
Code:
{"id": 1, "jsonrpc": "2.0", "method": "blockchain.scripthash.get_balance", "params":{"scripthash": "3EB89E41426A48CBE02E7BEDAEB8CF2B4922ED7D3069D31FA862F4F5AD5C989C"}}

It gets a little bit tricky here because to get the balance of an address, you really need to get the sum of any UTXOs who's scriptPubKey hashes to this hash. In the case of a classic P2PKH address, it will be the standard OP_DUP, OP_HASH160... script, with the pubkeyhash, extractable from the address.

You can see the docs for the Electrum protocol here: https://electrumx.readthedocs.io/en/latest/protocol-methods.html

If all this goes over your head, you might want to use a simpler API such as blockchain API: https://www.blockchain.com/api

The blockchain API is probably subject to rate-limiting though, so if many people use your app it might, as you say cost you. ElectrumX is open source and requires a bitcoind instance to work, so you can set it up yourself, but there are many of them running at the moment which you can already use to get started on your app right away.

Hope this helps.
legendary
Activity: 3472
Merit: 10611
Because I am a newbie, is there anyone who can address me how to achieve my end goal? Smiley

it depends on what you you want to do with all that. you may be better off installing a decent wallet and use that. wallets usually show your transaction history with all the additional info such as fees.

other wise you have to read the documentation and learn how to use the command line or JSON RPC. i suppose you can do it both with your bitcoin core full node and also with using remote Electrum nodes.
core: https://bitcoin.org/en/developer-reference#bitcoin-core-apis
electrum: https://electrumx.readthedocs.io/en/latest/

in bitcoin core listaddressgroupings and listtransactions commands return list of addresses and transactions.
in electrum blockchain.scripthash.get_balance and blockchain.scripthash.get_history return address balance and transaction history (only hashes you have to get the tx separately).
newbie
Activity: 17
Merit: 6
Hello,

I am trying to build a simple app that retrieve Bitcoin balance, transactions and fee for a given Public Wallet Address...

for example, if we get the following Address: 1GB2CgZ9a4yXFaaN2YfmTKuhZbomkpUfbH btc.com api woudl give me exactly what I need with two API calls:

- Balance: https://chain.api.btc.com/v3/address/1GB2CgZ9a4yXFaaN2YfmTKuhZbomkpUfbH
- Transactions/fees: https://chain.api.btc.com/v3/address/1GB2CgZ9a4yXFaaN2YfmTKuhZbomkpUfbH/tx

Because these services changes and often have some limitations (e.g. # of API calls per second/per IP), I would prefer to build the same results on my infrastructure...

my next steps are:

1) install a bitcoin Node in my infrastructure (do I need a full node? I would prefer to have something "lighter" to save data storage and bandwidth)....

2) create a code that interact with the node and retrieve what I need...

Because I am a newbie, is there anyone who can address me how to achieve my end goal? Smiley

sorry, I am not sure where to start....

Thank you all!
Jump to: