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?
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:
nc electrumx.kenrufe.com 50001
Then issue commands by copy-pasting them into your terminal, eg:
Subscribe to new blocks:
{"id": 1, "jsonrpc":"2.0", "method": "blockchain.headers.subscribe"}
Get the balance of an address:
{"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.htmlIf all this goes over your head, you might want to use a simpler API such as blockchain API:
https://www.blockchain.com/apiThe 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.