How to get the "BTC" abbreviation via command line?

2

I'm writing a module that connects to multiple wallets at once and I would like to have a way I can simply query the coin daemon for its coins abbreviation (not the "microcoins" as asked in a comment below, just the 3 character currency identifier).

Since my module also reads the coins config file, my only solution thus far is to add a parameter in the coins config file:

abbr=BTC

But I was wondering if there was a cleaner way to do this. A simple rpc command that I can pull the abbr from?

s4w3d0ff

Posted 2015-10-27T20:24:27.120

Reputation: 201

Do you mean BTC as opposed to mBTC or uBTC? I don't think I understand what you mean.Jannes 2015-10-28T00:36:57.323

I don't think there's any way to do this that's better than what you've come up with.Nick ODell 2015-10-30T03:19:44.457

It just surprises me that the Bitcoin software does not output "BTC" anywhere. I know that it is defined in the code, but I don't think there is an rpc call that ouputs "BTC". Maybe a future feature... I could always modify the source code of each coin and compile it... but that is going the wrong direction on my part.s4w3d0ff 2015-10-31T17:48:29.033

Answers

3

I will post my solution, but I still think there should be a cleaner way of doing this.

You would first need to open up (or create) the conf file for the coin which you wish to connect with then add abbr=BTC (or replace 'BTC' with whatever coin abbr you want).

You would then need to open up and read that conf file with your script/module. Since I am working with Python, here a function that does that:

def readCfg(location):
    cfg ={}
    with open(location) as f:
        for line in f:
            line = line.strip()
            if line and not line.startswith("#") and '=' in line: cfg[line.split('=', 1)[0]] = line.split('=', 1)[1]
        return cfg

cfg = readCfg('/home/username/.bitcoin/bitcoin.conf')
print(cfg['abbr'])

I think maybe having a documentation of this method done in other languages would be beneficial to the Bitcoin community. Feel free to expand on my answer until Bitcoin devs decide to add 'BTC' to the output of an rpc call.

s4w3d0ff

Posted 2015-10-27T20:24:27.120

Reputation: 201