<p>It is hex encoded byteString. You can use the Cardano serialization lib browser
<a href="https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-browser" rel="nofollow noreferrer">https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-browser</a></p>
<p>And the following code in javascript</p>
<pre><code>const addressBech32 = async () =&gt; {
  await Loader.load();
  const address = (await window.cardano.getUsedAddresses())[0];
  return Loader.Cardano.Address.from_bytes(
    Buffer.from(address, &quot;hex&quot;)
  ).to_bech32();
};
</code></pre>
<p>Where Loader is my loader to the above Library :) the Address class has a method for converting Hex encoded bytes to Address Bech 32 :</p>
<pre><code>class Loader {
  async load() {
    if (this._wasm) {
      return;
    }
    /**
     * @private
     */
    this._wasm = await import(
      &quot;./@emurgo/cardano-serialization-lib-browser/cardano_serialization_lib_bg&quot;
    );
  }

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

export default new Loader();
</code></pre>

CC BY-SA 4.0
2022-02-09T04:46:32.233Z
Could you elaborate on "loader to the above library".  I installed the link you posted using npm, copied this code to a file called "index.js" and then tried running the code with "node index.js".  I get an error saying "Loader is not defined".  I apologize if there is something obvious I'm missing here, I have a programming background but am brand new to javascript.
Richard
CC BY-SA 4.0
2022-02-10T03:03:53.737Z
Done, nothing obvious at all if you are new to JS. If you run it in node.js you do not need this...  it is only needed if it is going to run in the browser... put the above code in another file that you import in the file where you are going to use the script that gets the address.
Alicia Basilio
CC BY-SA 4.0
2022-02-10T06:55:45.843Z
I have tried copying the exact code into a file and importing that file and get an error saying only modules can import. If the only way to do this is to learn webpack and node so be it but I feel there has to be a simple way of doing this. that doesn't require learning all these new javascript tools  I'm not concerned about being in browser,  python or command line are fine too.  I just need a working script that I can run that will convert this string into a usable address.  I can figure out how to port it to my application if I can just figure that part out.
Richard
CC BY-SA 4.0
2022-02-10T06:56:27.283Z
in python this would be two lines of code:
import <stringConvert>
<stringConvert>.decode(encodedString)
Richard
CC BY-SA 4.0
2022-02-10T23:22:53.093Z
I found out there was a binary Bech32 that does the job.  Thank you for the help!
Richard
CC BY-SA 4.0
2022-02-11T01:59:26.363Z
For imporrting in ES6 notation you might change to .mjs file extention ... all your code should be handled in that way. If you do not want to do it that way you can use require() notation in normal .js files. I underestand your fustration, i am a native Python developer more thatn Js Developer. You can read about it here https://www.digitalocean.com/community/tutorials/js-modules-es6 .. but what you need to do is change your file to .mjs ... and keep it like that all over your project, or import using 'require' and export using module.exports=
Alicia Basilio
CC BY-SA 4.0
2022-02-07T05:04:54.830Z
2022-02-10T03:02:56.720Z
2022-02-10T03:02:56.720Z
Alicia Basilio
<p>According to the docs, this is a BaseAddress type, which is a hex representation in byte strings</p>
<p><a href="https://github.com/Berry-Pool/nami-wallet/blob/main/README.md#cardanogetusedaddresses" rel="nofollow noreferrer">https://github.com/Berry-Pool/nami-wallet/blob/main/README.md#cardanogetusedaddresses</a></p>

CC BY-SA 4.0
2022-02-07T05:31:21.987Z
ok. so how do i convert that to address format?
Richard
CC BY-SA 4.0
2022-02-08T04:28:45.610Z
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Community
CC BY-SA 4.0
2022-02-07T05:00:26.013Z
2022-02-07T05:00:26.013Z
caike
<p>If you can help me with this I will really appreciate it. I have worked through the token construction tutorial on Cardano docs <a href="https://docs.cardano.org/core-concepts/cardano-addresses" rel="nofollow noreferrer">https://docs.cardano.org/core-concepts/cardano-addresses</a>. Using the command line I can successfully create transactions</p>
<p>cardano-cli transaction-build-raw /<br />
--fee 0 /<br />
--tx-in ${TxHash}#$T{xIX} /<br />
--tx-out ${receiveAddress}+${amountToSend} /<br />
--out-file mat.raw</p>
<p>when running this command I can successfully send ada to my Nami wallet if I set the variable:</p>
<p>receiveAddress=&quot;addr_test1qq5vc9wurul0cd3f2n8fu5uahdaefp6r4rn6nq9tmnvdwzdgchadmnjxnqgaf4k3ju8t74jaj80uwdrcvnxfjmawzats23jjcl&quot;</p>
<p>This address can be obtained by clicking the nami wallet &quot;receive button&quot; and copying the address.
This part works fine.</p>
<p>I am trying to tie this transaction building command to a button in javascript.  To do this I am looking at CIP-30. <a href="https://cips.cardano.org/cips/cip30/" rel="nofollow noreferrer">https://cips.cardano.org/cips/cip30/</a>.  But when I use the injected javascript from Namie wallet</p>
<p>'''
let address = await cardano.getChangeAddress()
'''
the variable address is a string not in the proper format.
&quot;0028cc15dc1f3efc362954ce9e539dbb7b948743a8e7a980abdcd8d709a8c5faddce469811d4d6d1970ebf565d91dfc7347864cc996fae1757&quot;.
What is this format? How do I convert it to the Addr_test- string?</p>
<p>Thank you in advance!</p>

<address><nami>
How do I properly parse the CIP-30 output from NAMI to send a users wallet tokens?
# How do I properly parse the CIP-30 output from NAMI to send a users wallet tokens?

(Asked by: username_0 on 2022-02-07)

If you can help me with this I will really appreciate it. I have worked through the token construction tutorial on Cardano docs <https://docs.cardano.org/core-concepts/cardano-addresses>. Using the command line I can successfully create transactions

cardano-cli transaction-build-raw /  
--fee 0 /  
--tx-in ${TxHash}#$T{xIX} /  
--tx-out ${receiveAddress}+${amountToSend} /  
--out-file mat.raw

when running this command I can successfully send ada to my Nami wallet if I set the variable:

receiveAddress="addr\_test1qq5vc9wurul0cd3f2n8fu5uahdaefp6r4rn6nq9tmnvdwzdgchadmnjxnqgaf4k3ju8t74jaj80uwdrcvnxfjmawzats23jjcl"

This address can be obtained by clicking the nami wallet "receive button" and copying the address.
This part works fine.

I am trying to tie this transaction building command to a button in javascript. To do this I am looking at CIP-30. <https://cips.cardano.org/cips/cip30/>. But when I use the injected javascript from Namie wallet

'''
let address = await cardano.getChangeAddress()
'''
the variable address is a string not in the proper format.
"0028cc15dc1f3efc362954ce9e539dbb7b948743a8e7a980abdcd8d709a8c5faddce469811d4d6d1970ebf565d91dfc7347864cc996fae1757".
What is this format? How do I convert it to the Addr\_test- string?

Thank you in advance!

**Tags:** address, nami

---

## 2 answers

### Answer by username_1 on 2022-02-07. Score: 2

It is hex encoded byteString. You can use the Cardano serialization lib browser
https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-browser
And the following code in javascript
const addressBech32 = async () => {
  await Loader.load();
  const address = (await window.cardano.getUsedAddresses())[0];
  return Loader.Cardano.Address.from_bytes(
    Buffer.from(address, "hex")
  ).to_bech32();
};

Where Loader is my loader to the above Library :) the Address class has a method for converting Hex encoded bytes to Address Bech 32 :
class Loader {
  async load() {
    if (this._wasm) {
      return;
    }
    /**
     * @private
     */
    this._wasm = await import(
      "./@emurgo/cardano-serialization-lib-browser/cardano_serialization_lib_bg"
    );
  }

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

export default new Loader();

> **Comments:**
> **username_0**: Could you elaborate on "loader to the above library".  I installed the link you posted using npm, copied this code to a file called "index.js" and then tried running the code with "node index.js".  I get an error saying "Loader is not defined".  I apologize if there is something obvious I'm missing here, I have a programming background but am brand new to javascript.  
> **username_1**: Done, nothing obvious at all if you are new to JS. If you run it in node.js you do not need this...  it is only needed if it is going to run in the browser... put the above code in another file that you import in the file where you are going to use the script that gets the address.  
> **username_0**: I have tried copying the exact code into a file and importing that file and get an error saying only modules can import. If the only way to do this is to learn webpack and node so be it but I feel there has to be a simple way of doing this. that doesn't require learning all these new javascript tools  I'm not concerned about being in browser,  python or command line are fine too.  I just need a working script that I can run that will convert this string into a usable address.  I can figure out how to port it to my application if I can just figure that part out.  
> **username_0**: in python this would be two lines of code: import <stringConvert> <stringConvert>.decode(encodedString)  
> **username_0**: I found out there was a binary Bech32 that does the job.  Thank you for the help!  
> **username_1**: For imporrting in ES6 notation you might change to .mjs file extention ... all your code should be handled in that way. If you do not want to do it that way you can use require() notation in normal .js files. I underestand your fustration, i am a native Python developer more thatn Js Developer. You can read about it here https://www.digitalocean.com/community/tutorials/js-modules-es6 .. but what you need to do is change your file to .mjs ... and keep it like that all over your project, or import using 'require' and export using module.exports=  

---

### Answer by username_2 on 2022-02-07. Score: 0

According to the docs, this is a BaseAddress type, which is a hex representation in byte strings

<https://github.com/Berry-Pool/nami-wallet/blob/main/README.md#cardanogetusedaddresses>

> **Comments:**
> **username_0**: ok. so how do i convert that to address format?  
> **username_3**: As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).  

---

