7

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

2
  • 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
    Commented Sep 21, 2021 at 17:18
  • Please comment in the comment area only Commented Sep 21, 2021 at 20:01

2 Answers 2

9

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.

1
  • 1
    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. Commented Jun 11, 2021 at 8:28
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.