Bitcoin Forum
May 04, 2024, 06:17:30 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Architecture and code for retrieving Wallet Address balance and transactions  (Read 234 times)
FiNaR76 (OP)
Newbie
*
Offline Offline

Activity: 17
Merit: 6


View Profile
February 07, 2020, 05:14:06 AM
Merited by vapourminer (1), ABCbits (1)
 #1

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!
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10546



View Profile
February 07, 2020, 06:08:07 AM
Merited by ABCbits (1)
 #2

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).

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
unsigned_long_long
Jr. Member
*
Offline Offline

Activity: 39
Merit: 6


View Profile
February 09, 2020, 09:07:31 PM
 #3

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.
NotATether
Legendary
*
Offline Offline

Activity: 1596
Merit: 6728


bitcoincleanup.com / bitmixlist.org


View Profile WWW
February 14, 2020, 12:46:19 PM
 #4

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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
FiNaR76 (OP)
Newbie
*
Offline Offline

Activity: 17
Merit: 6


View Profile
February 16, 2020, 10:04:40 AM
 #5

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!
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10546



View Profile
February 17, 2020, 05:02:37 AM
 #6

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

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!