<p>You can also use <a href="https://www.npmjs.com/package/@stricahq/typhonjs" rel="nofollow noreferrer">typhonjs</a> used by typhonwallet. It's a Pure JS library not dependent on WASM.</p>
<p>Install</p>
<pre><code>npm i @stricahq/typhonjs
</code></pre>
<p>Usage</p>
<pre><code>const typhonjs =  require(&quot;@stricahq/typhonjs&quot;);

const bech32Address = typhonjs.utils
  .getAddressFromHex(&quot;012f4d0b584ecb52e4e4b8e78e4ce77a6f822e59ede3277305fd526b71824b2d2740284cf6a28e2a512cc4a00f41004c18ed728a0f7a04eb29&quot;)
  .getBech32();
</code></pre>

CC BY-SA 4.0
2022-03-30T09:38:11.243Z
I might appear clueless, but I am running code via python Flask. It means the javascript is executed client-side. In the background, everything is executed via python and ajax queries. Will I be able to execute this client side?
Lokinou
CC BY-SA 4.0
2022-03-30T13:52:40.577Z
Yes, you can execute this code client side :) @Lokinou
Pavan Vora
CC BY-SA 4.0
2022-03-30T05:23:03.403Z
2022-03-30T05:23:03.403Z
Pavan Vora
<p>First install the npm module:</p>
<pre><code>npm i @emurgo/cardano-serialization-lib-browser
</code></pre>
<p>Then you need a wasm loader module</p>
<pre><code>class wasm {
  async load() {
    if (this._wasm) return;
    /**
     * @private
     */
    this._wasm = await import(
      &quot;@emurgo/cardano-serialization-lib-browser/cardano_serialization_lib&quot;
    );
  }

  get Cardano() {
    return this._wasm;
  }
}

export default new wasm();
</code></pre>
<p>Then import into your module/component using:</p>
<pre><code>import WASMLoader from &quot;../../utils/Loader&quot;;
</code></pre>
<p>Now you should be able to use wasm module to convert the CBOR address into bech32 (addr1.., stake1.. etc)</p>
<pre><code>const getAddressToBech32 = async () =&gt; {
    await WASMLoader.load();
    const address = (await api.getUsedAddresses())[0];
    return WASMLoader.Cardano.Address.from_bytes(Buffer.from(address,&quot;hex&quot;)).to_bech32();
};
</code></pre>
<p>Now that you have a bech32 address you should be able to use with for blockfrost API queries</p>

CC BY-SA 4.0
2022-03-27T03:05:56.867Z
2022-03-27T03:05:56.867Z
intrinsic-values
<p>I have managed to retrive a user address from a dapp connector wallet using JS:</p>
<pre><code>api_promise = window.cardano.{wallet}.enable();
api_promise.then(function(api) {
  addr_promise = api.getUsedAddresses();
  addr_promise.then(
    function(addr) {
      value[0];  // this is a CBOR address !
...
</code></pre>
<p>I get this type of (presumably CBOR) address: <code>012f4d0b584ecb52e4e4b8e78e4ce77a6f822e59ede3277305fd526b71824b2d2740284cf6a28e2a512cc4a00f41004c18ed728a0f7a04eb29</code>
Apparently with some skill it could be read using this -&gt; <code>https://cbor.me</code>.</p>
<p><strong># Is there any method to extract a shelley <code>addr_34....</code> using JS or python?</strong></p>
<p>Working implementations are available in node.js, but I'm using flask (python + JS). And I'm struggling to make it work wit packages <code>cbor2</code> and <code>bech32</code>.
For example I tried <code>cbor2.loads(bytes(addr_str, 'utf-8'))</code> without success.</p>
<p>My further goal is to query blockfrost.</p>

<api><javascript><cbor><python>
Cbor address to bech32 type address in JS or python
# Cbor address to bech32 type address in JS or python

(Asked by: username_0 on 2022-03-24)

I have managed to retrive a user address from a dapp connector wallet using JS:
api_promise = window.cardano.{wallet}.enable();
api_promise.then(function(api) {
  addr_promise = api.getUsedAddresses();
  addr_promise.then(
    function(addr) {
      value[0];  // this is a CBOR address !
...

I get this type of (presumably CBOR) address: 012f4d0b584ecb52e4e4b8e78e4ce77a6f822e59ede3277305fd526b71824b2d2740284cf6a28e2a512cc4a00f41004c18ed728a0f7a04eb29
Apparently with some skill it could be read using this -> https://cbor.me.
# Is there any method to extract a shelley addr_34.... using JS or python?
Working implementations are available in node.js, but I'm using flask (python + JS). And I'm struggling to make it work wit packages cbor2 and bech32.
For example I tried cbor2.loads(bytes(addr_str, 'utf-8')) without success.
My further goal is to query blockfrost.

**Tags:** api, javascript, cbor, python

---

## 2 answers

### Answer by username_1 on 2022-03-30. Score: 2

You can also use typhonjs used by typhonwallet. It's a Pure JS library not dependent on WASM.
Install
npm i @stricahq/typhonjs

Usage
const typhonjs =  require("@stricahq/typhonjs");

const bech32Address = typhonjs.utils
  .getAddressFromHex("012f4d0b584ecb52e4e4b8e78e4ce77a6f822e59ede3277305fd526b71824b2d2740284cf6a28e2a512cc4a00f41004c18ed728a0f7a04eb29")
  .getBech32();

> **Comments:**
> **username_0**: I might appear clueless, but I am running code via python Flask. It means the javascript is executed client-side. In the background, everything is executed via python and ajax queries. Will I be able to execute this client side?  
> **username_1**: Yes, you can execute this code client side :) @Lokinou  

---

### Answer by username_2 on 2022-03-27. Score: 1

First install the npm module:
npm i @emurgo/cardano-serialization-lib-browser

Then you need a wasm loader module
class wasm {
  async load() {
    if (this._wasm) return;
    /**
     * @private
     */
    this._wasm = await import(
      "@emurgo/cardano-serialization-lib-browser/cardano_serialization_lib"
    );
  }

  get Cardano() {
    return this._wasm;
  }
}

export default new wasm();

Then import into your module/component using:
import WASMLoader from "../../utils/Loader";

Now you should be able to use wasm module to convert the CBOR address into bech32 (addr1.., stake1.. etc)
const getAddressToBech32 = async () => {
    await WASMLoader.load();
    const address = (await api.getUsedAddresses())[0];
    return WASMLoader.Cardano.Address.from_bytes(Buffer.from(address,"hex")).to_bech32();
};

Now that you have a bech32 address you should be able to use with for blockfrost API queries


---

