<p>This only works if it's an address embedding the payment and stake credential. You can use <code>cardano-address address inspect</code> locally. You could also use a tool like cardanoscan.io which when given an address to scan tells you the stake address associated as well.</p>
<p>Note that some addresses don't have stake addresses and other ones can have only pointers to stake registrations.</p>

CC BY-SA 4.0
2022-01-23T13:21:57.520Z
2022-01-23T13:21:57.520Z
Samuel Leathers
<p>Just for completeness, you can also use Haskell to decode the address into its components using a function like the one shown in the <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/main/code/week10/src/Week10/Deploy.hs#L39" rel="nofollow noreferrer">Plutus Pioneer Program</a>.</p>
<pre><code>tryReadStakeAddress :: String -&gt; Maybe Plutus.StakingCredential
tryReadStakeAddress = show . Plutus.addressStakingCredential . tryReadAddress

tryReadAddress :: String -&gt; Maybe Plutus.Address
tryReadAddress x = case deserialiseAddress AsAddressAny $ pack x of
    Nothing                                      -&gt; Nothing
    Just (AddressByron _)                        -&gt; Nothing
    Just (AddressShelley (ShelleyAddress _ p s)) -&gt; Just Plutus.Address
        { Plutus.addressCredential        = credentialLedgerToPlutus p
        , Plutus.addressStakingCredential = stakeReferenceLedgerToPlutus s
        }

credentialLedgerToPlutus :: Ledger.Credential a StandardCrypto -&gt; Plutus.Credential
credentialLedgerToPlutus (ScriptHashObj (ScriptHash h)) = Plutus.ScriptCredential $ Plutus.ValidatorHash $ toBuiltin $ hashToBytes h
credentialLedgerToPlutus (KeyHashObj (KeyHash h))       = Plutus.PubKeyCredential $ Plutus.PubKeyHash $ toBuiltin $ hashToBytes h

stakeReferenceLedgerToPlutus :: Ledger.StakeReference StandardCrypto -&gt; Maybe Plutus.StakingCredential
stakeReferenceLedgerToPlutus (StakeRefBase x)                   = Just $ StakingHash $ credentialLedgerToPlutus x
stakeReferenceLedgerToPlutus (StakeRefPtr (Ptr (SlotNo x) y z)) = Just $ StakingPtr (fromIntegral x) (fromIntegral y) (fromIntegral z)
stakeReferenceLedgerToPlutus StakeRefNull                       = Nothing
</code></pre>

CC BY-SA 4.0
2022-07-29T07:28:54.437Z
2022-07-29T07:28:54.437Z
Will
<p>As Samuel said, the address in question must contain the staking part in the first place.</p>
<p>cardano-address uses <a href="https://github.com/input-output-hk/bech32" rel="nofollow noreferrer">IOG's implementation of bech32</a>. Instead of using cardano-address you could also install bech32 instead and decode/encode the address.</p>
<pre><code>$ addr=addr1qxkmuf2gqzsm5ejxm2amrwuq3pcc02cw6tttgsgqgafj46klskg5jjufdyf4znw8sjn37enwn5ge5l66qsx8srrpg3tq8du7us
$ echo $addr | ./bech32 
01adbe254800a1ba6646dabbb1bb80887187ab0ed2d6b4410047532aeadf8591494b896913514dc784a71f666e9d119a7f5a040c780c614456
</code></pre>
<p>Now extract the last 57 bytes from the result as it is the staking address. Then you prefix that with the correct network tag (e0 for testnet and e1 for mainnet) and encode with bech32 to receive the staking address</p>
<pre><code>$ echo &quot;e1$(echo $addr | ./bech32 | tail -c 57)&quot; | ./bech32 stake
stake1u9rfyvw5pkeherf56lzxjaqlpxs53fjghl4ft6w2x8wpnwchfeam3
</code></pre>
<p>On a side note, be aware of the existence of franken addresses. A constructed address which has the payment part of one wallet and the staking part of another. This way I could pretend I am the owner of the stake delegated to the pool.</p>

CC BY-SA 4.0
2022-07-28T23:48:38.073Z
2023-03-21T14:41:50.157Z
2023-03-21T14:41:50.157Z
LACE pool
<p>If someone provides me with a payment address, how can I derive the staking address from the payment address?</p>
<p>This can be useful for example when we want to sent rewards to the people in return for staking to a pool.</p>

CC BY-SA 4.0
2022-01-23T22:46:42.407Z
Good question, surprised you didn't get more votes.
gRebel
<cardano-cli><cardano-node>
How can I derive the Staking address from a Payment address?
# How can I derive the Staking address from a Payment address?

(Asked by: username_0 on 2022-01-23)

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

This can be useful for example when we want to sent rewards to the people in return for staking to a pool.

**Tags:** cardano-cli, cardano-node
> **Comments:**
> **username_1**: Good question, surprised you didn't get more votes.  

---

## 3 answers

### Answer by username_2 on 2022-01-23. Score: 5

This only works if it's an address embedding the payment and stake credential. You can use `cardano-address address inspect` locally. You could also use a tool like cardanoscan.io which when given an address to scan tells you the stake address associated as well.

Note that some addresses don't have stake addresses and other ones can have only pointers to stake registrations.


---

### Answer by username_4 on 2022-07-28. Score: 3

As Samuel said, the address in question must contain the staking part in the first place.
cardano-address uses IOG's implementation of bech32. Instead of using cardano-address you could also install bech32 instead and decode/encode the address.
$ addr=addr1qxkmuf2gqzsm5ejxm2amrwuq3pcc02cw6tttgsgqgafj46klskg5jjufdyf4znw8sjn37enwn5ge5l66qsx8srrpg3tq8du7us
$ echo $addr | ./bech32 
01adbe254800a1ba6646dabbb1bb80887187ab0ed2d6b4410047532aeadf8591494b896913514dc784a71f666e9d119a7f5a040c780c614456

Now extract the last 57 bytes from the result as it is the staking address. Then you prefix that with the correct network tag (e0 for testnet and e1 for mainnet) and encode with bech32 to receive the staking address
$ echo "e1$(echo $addr | ./bech32 | tail -c 57)" | ./bech32 stake
stake1u9rfyvw5pkeherf56lzxjaqlpxs53fjghl4ft6w2x8wpnwchfeam3

On a side note, be aware of the existence of franken addresses. A constructed address which has the payment part of one wallet and the staking part of another. This way I could pretend I am the owner of the stake delegated to the pool.


---

### Answer by username_3 on 2022-07-29. Score: 0

Just for completeness, you can also use Haskell to decode the address into its components using a function like the one shown in the Plutus Pioneer Program.
tryReadStakeAddress :: String -> Maybe Plutus.StakingCredential
tryReadStakeAddress = show . Plutus.addressStakingCredential . tryReadAddress

tryReadAddress :: String -> Maybe Plutus.Address
tryReadAddress x = case deserialiseAddress AsAddressAny $ pack x of
    Nothing                                      -> Nothing
    Just (AddressByron _)                        -> Nothing
    Just (AddressShelley (ShelleyAddress _ p s)) -> Just Plutus.Address
        { Plutus.addressCredential        = credentialLedgerToPlutus p
        , Plutus.addressStakingCredential = stakeReferenceLedgerToPlutus s
        }

credentialLedgerToPlutus :: Ledger.Credential a StandardCrypto -> Plutus.Credential
credentialLedgerToPlutus (ScriptHashObj (ScriptHash h)) = Plutus.ScriptCredential $ Plutus.ValidatorHash $ toBuiltin $ hashToBytes h
credentialLedgerToPlutus (KeyHashObj (KeyHash h))       = Plutus.PubKeyCredential $ Plutus.PubKeyHash $ toBuiltin $ hashToBytes h

stakeReferenceLedgerToPlutus :: Ledger.StakeReference StandardCrypto -> Maybe Plutus.StakingCredential
stakeReferenceLedgerToPlutus (StakeRefBase x)                   = Just $ StakingHash $ credentialLedgerToPlutus x
stakeReferenceLedgerToPlutus (StakeRefPtr (Ptr (SlotNo x) y z)) = Just $ StakingPtr (fromIntegral x) (fromIntegral y) (fromIntegral z)
stakeReferenceLedgerToPlutus StakeRefNull                       = Nothing


---

