<p>perhaps the <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/src/Plutus.V1.Ledger.Contexts.html#pubKeyOutputsAt" rel="nofollow noreferrer">source code</a> will explain it better than me.</p>
<p>in any case I'll try to explain it here.</p>
<p><code>valuePaidTo</code> is defined as:</p>
<pre><code>{-# INLINABLE valuePaidTo #-}
-- | Get the total value paid to a public key address by a pending transaction.
valuePaidTo :: TxInfo -&gt; PubKeyHash -&gt; Value
valuePaidTo ptx pkh = mconcat (pubKeyOutputsAt pkh ptx)
</code></pre>
<p>the comment</p>
<pre><code>-- | Get the total value paid to a public key address by a pending 
</code></pre>
<p>should already give you answer</p>
<p>in any case, we see that in the definition of <code>valuePaidTo</code> the function <code>pubKeyOutputsAt</code> is used</p>
<p>that function is defined in <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/src/Plutus.V1.Ledger.Contexts.html#pubKeyOutputsA" rel="nofollow noreferrer">the same source file</a> just some lines above</p>
<p>in any case only having a look at the type signature should tell us a lot:</p>
<pre><code>pubKeyOutputsAt :: PubKeyHash -&gt; TxInfo -&gt; [Value]
</code></pre>
<p>from this, we know that <code>pubKeyOutputsAt</code> returns a list of <code>Value</code> (<code>[Value]</code>), which we can assume (and confirm by reading the source) that are all the <code>Value</code>s going to the <code>PublicKeyHash</code></p>
<p>and from Haskell we know that <code>mconcat</code> (used in <code>valuePaidTo</code>) is something like the following</p>
<pre><code>mconcat :: Monoid a =&gt; [a] -&gt; a
</code></pre>
<p>where <code>Monoid</code> are &quot;things with a binary operation that returns something of the same type&quot;, and <code>Value</code>s happen to be a valid instance of <code>Monoid</code> where the operation acts as a &quot;sum&quot;</p>
<p>so what <code>valuePaidTo</code> is doing is</p>
<ol>
<li>take <strong>all</strong> the values going to the given <code>PublicKeyHash</code></li>
<li>&quot;sum&quot; them</li>
</ol>
<p>in your case then the output lovelaces value would be <code>107950820</code></p>

CC BY-SA 4.0
2022-06-19T12:51:40.243Z
2022-06-19T12:51:40.243Z
Michele Nuzzi
<p>How does valuePaidTo work ? Does it give the value paid by the script to the pubkeyhash or is it the total value of the pubkeyhash for the pending transactions ?
Consider the following TxOut</p>
<pre><code>txOutputs = [ 
   TxOut {
       txOutAddress = Address {
           addressCredential = PubKeyCredential &quot;80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7&quot;,
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [
                (,Map [(&quot;&quot;,87950820)])
            ]), 
        txOutDatumHash = Nothing
    },
    TxOut {
        txOutAddress = Address {
            addressCredential =
                ScriptCredential &quot;d909e024ee4ed177cee1ec2b93de9afcf1ca1cb082f3af67ffa6a6e0&quot;,
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [(,Map [(&quot;&quot;,2000000)]),
            (64636464636161,Map [(&quot;T1&quot;,1)])]),
        txOutDatumHash = Just 5b3b53a06a4c34209a6278e9c89b570e9bf76e1e040cd528a7f1bf4ce3535742
    }, 
    TxOut {
        txOutAddress = Address {
            addressCredential = PubKeyCredential &quot;80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7&quot;,
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [(,Map [(&quot;&quot;,20000000)])]),
        txOutDatumHash = Nothing
    }
],
</code></pre>
<p>In this case the script is paying <code>20_000_000</code> to the pubkeyhash <code>80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7</code></p>
<p>Will <code>valuePaidTo</code> output <code>20_000_000</code> or <code>107_950_820</code> ?</p>

<plutus><plutus-pioneer-program><transaction><decentralized-applications><plutustx>
How does valuePaidTo work?
# How does valuePaidTo work?

(Asked by: username_0 on 2022-06-19)

How does valuePaidTo work ? Does it give the value paid by the script to the pubkeyhash or is it the total value of the pubkeyhash for the pending transactions ?
Consider the following TxOut
txOutputs = [ 
   TxOut {
       txOutAddress = Address {
           addressCredential = PubKeyCredential "80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7",
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [
                (,Map [("",87950820)])
            ]), 
        txOutDatumHash = Nothing
    },
    TxOut {
        txOutAddress = Address {
            addressCredential =
                ScriptCredential "d909e024ee4ed177cee1ec2b93de9afcf1ca1cb082f3af67ffa6a6e0",
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [(,Map [("",2000000)]),
            (64636464636161,Map [("T1",1)])]),
        txOutDatumHash = Just 5b3b53a06a4c34209a6278e9c89b570e9bf76e1e040cd528a7f1bf4ce3535742
    }, 
    TxOut {
        txOutAddress = Address {
            addressCredential = PubKeyCredential "80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7",
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [(,Map [("",20000000)])]),
        txOutDatumHash = Nothing
    }
],

In this case the script is paying 20_000_000 to the pubkeyhash 80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7
Will valuePaidTo output 20_000_000 or 107_950_820 ?

**Tags:** plutus, plutus-pioneer-program, transaction, decentralized-applications, plutustx

---

## 1 answers

### Answer by username_1 on 2022-06-19. Score: 0 | Accepted answer

perhaps the source code will explain it better than me.
in any case I'll try to explain it here.
valuePaidTo is defined as:
{-# INLINABLE valuePaidTo #-}
-- | Get the total value paid to a public key address by a pending transaction.
valuePaidTo :: TxInfo -> PubKeyHash -> Value
valuePaidTo ptx pkh = mconcat (pubKeyOutputsAt pkh ptx)

the comment
-- | Get the total value paid to a public key address by a pending 

should already give you answer
in any case, we see that in the definition of valuePaidTo the function pubKeyOutputsAt is used
that function is defined in the same source file just some lines above
in any case only having a look at the type signature should tell us a lot:
pubKeyOutputsAt :: PubKeyHash -> TxInfo -> [Value]

from this, we know that pubKeyOutputsAt returns a list of Value ([Value]), which we can assume (and confirm by reading the source) that are all the Values going to the PublicKeyHash
and from Haskell we know that mconcat (used in valuePaidTo) is something like the following
mconcat :: Monoid a => [a] -> a

where Monoid are "things with a binary operation that returns something of the same type", and Values happen to be a valid instance of Monoid where the operation acts as a "sum"
so what valuePaidTo is doing is

take all the values going to the given PublicKeyHash
"sum" them

in your case then the output lovelaces value would be 107950820


---

