<p>I do not think it is possible to achive this in plain bech32, you need to convert it to hex and than back to bech32 to get retrieve the bech32 stake address.</p>
<p>First you decode the bech32 shelley address</p>
<p>For example converting the address <code>addr1qxdvcswn0exwc2vjfr6u6f6qndfhmk94xjrt5tztpelyk4yg83zn9d4vrrtzs98lcl5u5q6mv7ngmg829xxvy3g5ydls7c76wu</code></p>
<p>gives us</p>
<p><code>019acc41d37e4cec299248f5cd27409b537dd8b53486ba2c4b0e7e4b54883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f</code></p>
<p>Now, the Stake part of the address is the last 56 bytes of it, which gives us <code>883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f</code>.</p>
<p>Converting this to a bech32, we will retrieve the associated stake key <code>stake1uxyrc3fjk6kp343gznlu06w2qddk0f5d5r4znrxzg52zxlclk0hlq</code>.</p>
<p>Just a reminder that the address can be mangled, so the owner of the stake rights might not be the same person as the owner of the payment funds.</p>

CC BY-SA 4.0
2021-06-11T08:28:27.130Z
Thanks this is what I tried. The problem I had was that the bech32 library I am using restricts the length of the encoded data to 90 characters. I found the limit can be changed so I can decode the address now.
Mark Gibbons
CC BY-SA 4.0
2021-06-11T08:01:39.980Z
2021-06-11T08:01:39.980Z
Marek Mahut - StakeNuts
<p>Just a side-note to Marek's answer, don't forget to append the prefix to the stake part!</p>
<p>In this case e1:</p>
<pre><code>e1883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f
</code></pre>
<p>See: <a href="https://cardano.stackexchange.com/questions/4046/bech32-encoding-stake-address-from-shelley-address-in-javascript-returning-wrong/">Bech32 encoding stake address from Shelley address in JavaScript returning wrong value</a></p>

CC BY-SA 4.0
2021-10-13T07:32:50.360Z
2021-10-13T07:32:50.360Z
1000101
<p>I am looking to get the bech32 stake address from a bech32 shelley address. I think I have to decode the shelley address, take the stake address part and encode it again.</p>
<p>I looked here: <a href="https://github.com/cardano-foundation/CIPs/blob/master/CIP-0019/CIP-0019.md#shelley-addresses" rel="noreferrer">https://github.com/cardano-foundation/CIPs/blob/master/CIP-0019/CIP-0019.md#shelley-addresses</a></p>
<p>But I did not find enough details to do this. Can anyone give me more exact information?</p>
<p>I am using the javascript bech32 library: <a href="https://www.npmjs.com/package/bech32" rel="noreferrer">https://www.npmjs.com/package/bech32</a></p>

CC BY-SA 4.0
2021-09-21T17:18:56.140Z
Did you manage to solve this problem? I'm trying to extract the stake address from shelley address using java. any tips would be appreciated tks
Thiago S
CC BY-SA 4.0
2021-09-21T20:01:04.480Z
Please comment in the comment area only
Aron Neewart
<cardano-address>
Extract the bech32 stake address from a shelly address in javascript
# Extract the bech32 stake address from a shelly address in javascript

(Asked by: username_0 on 2021-06-11)

I am looking to get the bech32 stake address from a bech32 shelley address. I think I have to decode the shelley address, take the stake address part and encode it again.

I looked here: <https://github.com/cardano-foundation/CIPs/blob/master/CIP-0019/CIP-0019.md#shelley-addresses>

But I did not find enough details to do this. Can anyone give me more exact information?

I am using the javascript bech32 library: <https://www.npmjs.com/package/bech32>

**Tags:** cardano-address
> **Comments:**
> **username_1**: Did you manage to solve this problem? I'm trying to extract the stake address from shelley address using java. any tips would be appreciated tks  
> **username_2**: Please comment in the comment area only  

---

## 2 answers

### Answer by username_3 on 2021-06-11. Score: 9 | Accepted answer

I do not think it is possible to achive this in plain bech32, you need to convert it to hex and than back to bech32 to get retrieve the bech32 stake address.

First you decode the bech32 shelley address

For example converting the address `addr1qxdvcswn0exwc2vjfr6u6f6qndfhmk94xjrt5tztpelyk4yg83zn9d4vrrtzs98lcl5u5q6mv7ngmg829xxvy3g5ydls7c76wu`

gives us

`019acc41d37e4cec299248f5cd27409b537dd8b53486ba2c4b0e7e4b54883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f`

Now, the Stake part of the address is the last 56 bytes of it, which gives us `883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f`.

Converting this to a bech32, we will retrieve the associated stake key `stake1uxyrc3fjk6kp343gznlu06w2qddk0f5d5r4znrxzg52zxlclk0hlq`.

Just a reminder that the address can be mangled, so the owner of the stake rights might not be the same person as the owner of the payment funds.

> **Comments:**
> **username_0**: Thanks this is what I tried. The problem I had was that the bech32 library I am using restricts the length of the encoded data to 90 characters. I found the limit can be changed so I can decode the address now.  

---

### Answer by username_4 on 2021-10-13. Score: 4

Just a side-note to Marek's answer, don't forget to append the prefix to the stake part!
In this case e1:
e1883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f

See: Bech32 encoding stake address from Shelley address in JavaScript returning wrong value


---

