Convert Cardano Wallet Address to Stake Address Key

If someone provides me with a payment address, how can I derive the staking address from the payment address?

Cardano uses bech32. Install bech32 instead and decode/encode the address.

Download the bech32 tool as part of cardano-wallet from github

# or if on mac

tar -xf cardano-wallet-v2022-12-14-linux64.tar.gz
rm cardano-wallet-v2022-12-14-linux64.tar.gz
cd cardano-wallet-v2022-12-14-linux64

Let’s say you have address

$ set addr addr1q9f2prypgqkrmr5497d8ujl4s4qu9hx0w6kruspdkjyudc2xjgcagrdn0jxnf47yd96p7zdpfzny30l2jh5u5vwurxasjwukdr
$ echo "e1$(echo $addr | ./bech32 | tail -c 57)" | ./bech32 stake

If you wanted to do the equivalent in python:

def resolve_addr2stake(address: str) -> str:
     same as 'echo "e1$(echo {address} | ./bech32 | tail -c 57)" |./bech32 stake'
     It may be quicker to cache the address, result in a lookup table
    :param address: wallet address, such as
    then last 56 bytes
    then convert to bech32

    :return: stake key, such as
    absolute_path = os.path.dirname(__file__)
    relative_path = "cardano-wallet/bech32"
    full_path = os.path.join(absolute_path, relative_path)

    p1 = subprocess.Popen(["echo", address], stdout=subprocess.PIPE)
    p2 =[full_path], stdin=p1.stdout, capture_output=True)
    s = p2.stdout.strip().decode('utf-8')
    p3 = subprocess.Popen(["echo", f"e1{s[-56:]}"], stdout=subprocess.PIPE)
    p4 =[full_path, 'stake'], stdin=p3.stdout, capture_output=True)
    return p4.stdout.strip().decode('utf-8')

Update: There is a better way with direct python code, no need for the command line sys calls.

See this post

Leave a Reply

Your email address will not be published. Required fields are marked *