Blockchain API? (fetch ada balance)


#1

I’d like to make a little script to keep track of my ADA.
Poke an API, with my address as an argument, and it would list my balance. Something like that.
The only thing I’ve found was https://cardanodocs.com/technical/wallet/api/v1/ and it seems I can only interact with a local running deadalus wallet, but my web linux box does not have access to my wallet box.
I then tried to parse pages on https://cardanoexplorer.com/ but they have a browser validator so I didn’t continue forcefully :slight_smile:
Anyone could point me in the right direction as to how to accomplish this?
Thank you,


#2

I think cardano-sl is what I need.


#3

Don’t know whether https://adatracker.com/ will do what you want or not (browser validator?) but if so I guess it would be easier than the cardano-sl route! :grin:


#4

Yep. You can use https://cardanoexplorer.com/ if you don’t want to deploy your own instance of cardano-sl. There’s a JSON API for the Explorer. I don’t know if there’s documentation on it, but here’s the source.

To query balance of an address:

curl -s "https://cardanoexplorer.com/api/addresses/summary/$address" |
python3 -c "import sys, json; print(float(json.load(sys.stdin)['Right']['caBalance']['getCoin'])/1000000)"

#5

LOL literally this like the 4th different place of instruction … PLease can we have only 1 … this is crazy …


#6

Is this even possible? Every time you make a transaction, it sends the balance to a newly generated address - right?

So you could do it, but you would have to type your address in everytime, because the address changed.

I say this because I was going to make an app (I write apps) that could show me my ADA balance on my phone (I get payments from people so it does change every day), however as soon as I started thinking about it, I hit this issue.


#7

Yup, imo, you have to know the root of HD wallet in order to be able to find all the derivative addresses, at least that’s how Daedalus does it. So if you want to track all your addresses - your app has to deal with seeds =\


#8

The receive address does not change unless you request a new one.


#9

That’s right, but if you send ADA, then all the change goes to another address. So tracking a single address only shows you full balance if you have no outgoing transaction.


#10

Thanks Vantuz, I did not know that. Never sent any ADA! :slight_smile:


#11

UTxO is designed in such a way so separate addresses would not make much sense, and only a wallet allows owner to know that all the addresses are connected. I think the only way is to design a full-wallet app, which might be tricky as hell. So the best solution would be to wait for an official Daedalus for mobile platforms :slight_smile:


#12

Yup, that kinda annoyed me at the beginning that I can’t chose where change is gonna go, cuz I also like to use explorers, and open wallet only when I need to make a transaction, but each outgoing transaction turned my wallet into a garland of addresses. But eh, whatcha gonna do ¯\_(ツ)_/¯


#13

Yea, that is the conclusion I came to… so too hard. lol.