<p>I am building a PlutusTx V1 Smart Contract for NFT Royalty distribution. Part of that requires totaling up the amount of Lovelace sent to the contract from the most recent tx. I came up with the following function to try and accomplish this:</p>
<pre><code>{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE DeriveGeneric  #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NamedFieldPuns #-}

import Prelude                        qualified as P

import PlutusTx                       (makeIsDataIndexed)
import PlutusTx.Prelude               as Tx hiding (Semigroup(..), unless)
import PlutusTx.Builtins              

import Ledger                         hiding (singleton)
import Ledger.Constraints             qualified as Constraints
import Plutus.Script.Utils.V1.Scripts qualified as Scripts
import Ledger.Typed.Scripts
import Ledger.Ada                     as Ada
import Ledger.Value
import Plutus.V1.Ledger.Tx

import Plutus.Contract
import Data.Aeson                     
import GHC.Generics                   (Generic)

{-# OPTIONS_GHC -fno-warn-unused-imports #-}

totalAdaAmnt :: TxInfo -&gt; Integer 
totalAdaAmnt TxInfo{txInfoOutputs} = 
    let valueSum = foldMap (Ledger.txOutValue . Ledger.TxOut) txInfoOutputs
    in valueOf valueSum Ada.adaSymbol Ada.adaToken
</code></pre>
<p>But when I try to compile, I get the following error:</p>
<pre><code>error:
    • Couldn't match expected type ‘Ledger.Value.Value’
                  with actual type ‘cardano-api-1.35.4:Cardano.Api.Value.Lovelace’
    • In the first argument of ‘valueOf’, namely ‘valueSum’
      In the expression: valueOf valueSum Ada.adaSymbol Ada.adaToken
      In the expression:
        let valueSum = foldMap (Ledger.txOutValue . Ledger.TxOut) txInfoOutputs
        in valueOf valueSum Ada.adaSymbol Ada.adaToken
   |
42 |     in valueOf valueSum Ada.adaSymbol Ada.adaToken
</code></pre>
<p>This is my first contract and I really don't know how to resolve this error. Ledger is key to many different parts of my code, whereas I'm not using the Cardano-api package anywhere except for in this function. Is there a Ledger equivalent for getting Ada amounts from previous script Txs? Or vice versa?
I looked throughout the <a href="https://input-output-hk.github.io/plutus/master/" rel="nofollow noreferrer">newly hosted Haddock docs</a> for PlutusTx and couldn't find any work around, so any help is immensely appreciated!</p>

CC BY-SA 4.0
2023-04-02T15:28:34.830Z
Could you also mention your imports?
Sourabh
CC BY-SA 4.0
2023-04-03T00:40:55.640Z
@Sourabh yes I'll edit the question to include them
theArchitect
<plutus><smart-contract><plutustx>
PlutusTx TxInfo Type Mismatch
# PlutusTx TxInfo Type Mismatch

(Asked by: username_0 on 2023-04-01)

I am building a PlutusTx V1 Smart Contract for NFT Royalty distribution. Part of that requires totaling up the amount of Lovelace sent to the contract from the most recent tx. I came up with the following function to try and accomplish this:
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE DeriveGeneric  #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NamedFieldPuns #-}

import Prelude                        qualified as P

import PlutusTx                       (makeIsDataIndexed)
import PlutusTx.Prelude               as Tx hiding (Semigroup(..), unless)
import PlutusTx.Builtins              

import Ledger                         hiding (singleton)
import Ledger.Constraints             qualified as Constraints
import Plutus.Script.Utils.V1.Scripts qualified as Scripts
import Ledger.Typed.Scripts
import Ledger.Ada                     as Ada
import Ledger.Value
import Plutus.V1.Ledger.Tx

import Plutus.Contract
import Data.Aeson                     
import GHC.Generics                   (Generic)

{-# OPTIONS_GHC -fno-warn-unused-imports #-}

totalAdaAmnt :: TxInfo -> Integer 
totalAdaAmnt TxInfo{txInfoOutputs} = 
    let valueSum = foldMap (Ledger.txOutValue . Ledger.TxOut) txInfoOutputs
    in valueOf valueSum Ada.adaSymbol Ada.adaToken

But when I try to compile, I get the following error:
error:
    • Couldn't match expected type ‘Ledger.Value.Value’
                  with actual type ‘cardano-api-1.35.4:Cardano.Api.Value.Lovelace’
    • In the first argument of ‘valueOf’, namely ‘valueSum’
      In the expression: valueOf valueSum Ada.adaSymbol Ada.adaToken
      In the expression:
        let valueSum = foldMap (Ledger.txOutValue . Ledger.TxOut) txInfoOutputs
        in valueOf valueSum Ada.adaSymbol Ada.adaToken
   |
42 |     in valueOf valueSum Ada.adaSymbol Ada.adaToken

This is my first contract and I really don't know how to resolve this error. Ledger is key to many different parts of my code, whereas I'm not using the Cardano-api package anywhere except for in this function. Is there a Ledger equivalent for getting Ada amounts from previous script Txs? Or vice versa?
I looked throughout the newly hosted Haddock docs for PlutusTx and couldn't find any work around, so any help is immensely appreciated!

**Tags:** plutus, smart-contract, plutustx
> **Comments:**
> **username_1**: Could you also mention your imports?  
> **username_0**: @Sourabh yes I'll edit the question to include them  

---

## 0 answers

