<p>The problem is that on the LHS you have:</p>
<pre><code>StakeRefPtr (Ptr (SlotNo x) y z)
</code></pre>
<p>but <code>StakeRefPtr</code> is defined (in <code>cardano-ledger</code> repo, file <code>libs/cardano-ledger-core/src/Cardano/Ledger/Credential.hs</code>) as:</p>
<pre><code>   | StakeRefPtr !Ptr
</code></pre>
<p>and <code>Ptr</code> is defined as:</p>
<pre><code>data Ptr = Ptr !SlotNo !TxIx !CertIx
</code></pre>
<p>and <code>TxIx</code> is defined as:</p>
<pre><code>newtype TxIx = TxIx Word64
</code></pre>
<p>That means, to get your code closer to working you should try:</p>
<pre><code>stakeReferenceLedgerToPlutus :: Ledger.StakeReference StandardCrypto -&gt; Maybe Plutus.StakingCredential
stakeReferenceLedgerToPlutus (StakeRefPtr (Ptr (SlotNo x) (TxIx y) z)) = Just $ StakingPtr (fromIntegral x) (fromIntegral y) (fromIntegral z)
</code></pre>
<p>You probably also need to do the same for the <code>z</code> which is defined as a:</p>
<pre><code>newtype CertIx = CertIx Word64
</code></pre>

CC BY-SA 4.0
2022-09-24T09:49:20.937Z
Thanks! Pattern matching to get the wrapped type makes complete sense.
Will
CC BY-SA 4.0
2022-09-23T08:46:39.437Z
2022-09-23T08:46:39.437Z
Erik de Castro Lopo
<p>I am using the following function from the Plutus pioneer program:</p>
<pre><code>stakeReferenceLedgerToPlutus :: Ledger.StakeReference StandardCrypto -&gt; Maybe Plutus.StakingCredential
stakeReferenceLedgerToPlutus (StakeRefPtr (Ptr (SlotNo x) y z)) = Just $ StakingPtr (fromIntegral x) (fromIntegral y) (fromIntegral z)
</code></pre>
<p>But the latest release of Plutus-apps seems to require a change, because <strong><code>fromIntegral y</code></strong> does not work anymore. See error below:</p>
<pre><code>error:
    • No instance for (Integral Cardano.Ledger.BaseTypes.TxIx)
        arising from a use of ‘fromIntegral’
    • In the second argument of ‘StakingPtr’, namely ‘(fromIntegral y)’
</code></pre>
<p>The same is true for <strong><code>fromIntegral z</code></strong> but for <code>Cardano.Ledger.BaseTypes.CertIx</code>.</p>
<p>Any help is appreciated.</p>

<plutus><ledger>
How to get Integer from Cardano.Ledger.BaseTypes.TxIx
# How to get Integer from Cardano.Ledger.BaseTypes.TxIx

(Asked by: username_0 on 2022-09-17)

I am using the following function from the Plutus pioneer program:
stakeReferenceLedgerToPlutus :: Ledger.StakeReference StandardCrypto -> Maybe Plutus.StakingCredential
stakeReferenceLedgerToPlutus (StakeRefPtr (Ptr (SlotNo x) y z)) = Just $ StakingPtr (fromIntegral x) (fromIntegral y) (fromIntegral z)

But the latest release of Plutus-apps seems to require a change, because fromIntegral y does not work anymore. See error below:
error:
    • No instance for (Integral Cardano.Ledger.BaseTypes.TxIx)
        arising from a use of ‘fromIntegral’
    • In the second argument of ‘StakingPtr’, namely ‘(fromIntegral y)’

The same is true for fromIntegral z but for Cardano.Ledger.BaseTypes.CertIx.
Any help is appreciated.

**Tags:** plutus, ledger

---

## 1 answers

### Answer by username_1 on 2022-09-23. Score: 2 | Accepted answer

The problem is that on the LHS you have:
StakeRefPtr (Ptr (SlotNo x) y z)

but StakeRefPtr is defined (in cardano-ledger repo, file libs/cardano-ledger-core/src/Cardano/Ledger/Credential.hs) as:
   | StakeRefPtr !Ptr

and Ptr is defined as:
data Ptr = Ptr !SlotNo !TxIx !CertIx

and TxIx is defined as:
newtype TxIx = TxIx Word64

That means, to get your code closer to working you should try:
stakeReferenceLedgerToPlutus :: Ledger.StakeReference StandardCrypto -> Maybe Plutus.StakingCredential
stakeReferenceLedgerToPlutus (StakeRefPtr (Ptr (SlotNo x) (TxIx y) z)) = Just $ StakingPtr (fromIntegral x) (fromIntegral y) (fromIntegral z)

You probably also need to do the same for the z which is defined as a:
newtype CertIx = CertIx Word64

> **Comments:**
> **username_0**: Thanks! Pattern matching to get the wrapped type makes complete sense.  

---

