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

<p>You would first need to <a href="https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File" rel="nofollow">open up (or create) the conf</a> file for the coin which you wish to connect with then add <code>abbr=BTC</code> (or replace 'BTC' with whatever coin abbr you want).</p>

<p>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:</p>



<pre><code>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'])
</code></pre>

<p><strong><em>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.</em></strong></p>

CC BY-SA 3.0
2015-11-01T19:45:04.127Z
2016-04-19T18:30:19.083Z
2016-04-19T18:30:19.083Z
s4w3d0ff
<p>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).</p>

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

<pre><code>abbr=BTC
</code></pre>

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

CC BY-SA 3.0
2015-10-28T00:36:57.323Z
Do you mean BTC as opposed to mBTC or uBTC? I don't think I understand what you mean.
Jannes
CC BY-SA 3.0
2015-10-30T03:19:44.457Z
I don't think there's any way to do this that's better than what you've come up with.
Nick ODell
CC BY-SA 3.0
2015-10-31T17:48:29.033Z
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
<bitcoind><client><json-rpc><python>
How to get the "BTC" abbreviation via command line?
s4w3d0ff
# How to get the "BTC" abbreviation via command line?

(Asked by: username_0 on 2015-10-27)

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?

**Tags:** bitcoind, client, json-rpc, python

> **Comments:**
> **username_1**: Do you mean BTC as opposed to mBTC or uBTC? I don't think I understand what you mean.  
> **username_2**: I don't think there's any way to do this that's better than what you've come up with.  
> **username_0**: 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.  

---

## 1 answers

### Answer by username_0 on 2015-11-01. Score: 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.


---

