<p>Looking at source code of <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/src/Plutus.V1.Ledger.Contexts.html#scriptOutputsAt" rel="nofollow noreferrer">scriptOutputsAt</a>, <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/src/Plutus.V1.Ledger.Contexts.html#pubKeyOutputsAt" rel="nofollow noreferrer">pubKeyOutputsAt</a> and <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/src/Plutus.V1.Ledger.Contexts.html#valueLockedBy" rel="nofollow noreferrer">valueLockedBy</a> I think, that (correct me if I wrong):</p>
<ol>
<li>One important think to note right away, is that <code>pubKeyOutputsAt</code> requires <code>PubKeyHash</code> as first argument, so <code>pubKeyOutputsAt scptAddress ...</code> won't type check, if script hash used as <code>scptAddress</code> (otherwise - naming is a bit misleading =) ). Script hash defines script address, and public key, which defines public key hash, <a href="https://cardano.stackexchange.com/a/3853/5017">used to derive a Cardano wallet address</a>.</li>
<li><code>scriptOutputsAt ownHash</code> <em>is not</em> equivalent to <code>pubKeyOutputsAt pubKeyHash</code> (note: <code>pubKeyHashs</code> for <code>pubKeyOutputsAt</code>, not <code>scptAddress</code>). <code>pubKeyOutputsAt</code> is <code>values paid to a public key address by a pending transaction</code> (when/if transaction succeeds). <code>scriptOutputsAt</code> is basically the same, but for scripts - values paid to a script address (defined by hash) by current transaction. So <code>scriptOutputsAt ownHash</code> will get you <code>Value</code> that <em>will</em> be paid to the current script (the script that does current validation) when transaction succeeds.</li>
<li><code>valueLockedBy</code> uses <code>scriptOutputsAt</code> under the hood, applying one extra step to accumulate total <code>Value</code> (i.e. go from <code>[(DatumHash, Value)]</code> to just <code>Value</code> summing values from list). So it will give you total <code>Value</code> that <em>will</em> be paid to a script (and locked by that script). So <code>valueLockedBy (scriptContextInfoTx ctx) ownHash</code> is <em>not</em> the total <code>Value</code> of UTxOs that currently locked by the current script, but total <code>Value</code> of UTxOs which <em>will</em> be produced by this transaction and <em>will</em> be locked at the current script when transaction succeeds.</li>
<li>So, <code>(valueLockedBy (scriptContextInfoTx ctx) ownHash)</code> and <code>fold $ pubKeyOutputsAt pubKeyHash (scriptContextInfoTx ctx)</code> are not the same in principle, as former uses script hash, and latter - public key hash , giving value for different kinds of addresses.</li>
</ol>

CC BY-SA 4.0
2022-02-22T21:18:53.817Z
Yes in my example scptAddress is the PubKeyHash associated with the script. Sorry if this was misleading. But essentially, in point 4 you are saying that the types of parameters differ, but they both do return the same result correct?
Philip DiSarro
CC BY-SA 4.0
2022-02-03T08:27:39.457Z
2022-02-03T08:53:09.687Z
2022-02-03T08:53:09.687Z
Mikhail Lazarev
<p>Is the line
<code>scriptOutputsAt ownHash</code> equivalent to <code>pubKeyOutputsAt scrptAddress</code>?</p>
<p>More importantly, is <code>(valueLockedBy (scriptContextInfoTx ctx) ownHash)</code> just the sum of the outputs at the script address? IE is it the same as</p>
<pre><code>let values = pubKeyOutputsAt scptAddress (scriptContextInfoTx ctx) in fold values
</code></pre>

<plutus><context>
PublicKeyOutputs at Script Address vs ScriptOutputsAt Validator Hash vs valueLockedBy
# PublicKeyOutputs at Script Address vs ScriptOutputsAt Validator Hash vs valueLockedBy

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

Is the line
scriptOutputsAt ownHash equivalent to pubKeyOutputsAt scrptAddress?
More importantly, is (valueLockedBy (scriptContextInfoTx ctx) ownHash) just the sum of the outputs at the script address? IE is it the same as
let values = pubKeyOutputsAt scptAddress (scriptContextInfoTx ctx) in fold values

**Tags:** plutus, context

---

## 1 answers

### Answer by username_1 on 2022-02-03. Score: 0

Looking at source code of [scriptOutputsAt](https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/src/Plutus.V1.Ledger.Contexts.html#scriptOutputsAt), [pubKeyOutputsAt](https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/src/Plutus.V1.Ledger.Contexts.html#pubKeyOutputsAt) and [valueLockedBy](https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/src/Plutus.V1.Ledger.Contexts.html#valueLockedBy) I think, that (correct me if I wrong):

1. One important think to note right away, is that `pubKeyOutputsAt` requires `PubKeyHash` as first argument, so `pubKeyOutputsAt scptAddress ...` won't type check, if script hash used as `scptAddress` (otherwise - naming is a bit misleading =) ). Script hash defines script address, and public key, which defines public key hash, [used to derive a Cardano wallet address](https://cardano.stackexchange.com/a/3853/5017).
2. `scriptOutputsAt ownHash` *is not* equivalent to `pubKeyOutputsAt pubKeyHash` (note: `pubKeyHashs` for `pubKeyOutputsAt`, not `scptAddress`). `pubKeyOutputsAt` is `values paid to a public key address by a pending transaction` (when/if transaction succeeds). `scriptOutputsAt` is basically the same, but for scripts - values paid to a script address (defined by hash) by current transaction. So `scriptOutputsAt ownHash` will get you `Value` that *will* be paid to the current script (the script that does current validation) when transaction succeeds.
3. `valueLockedBy` uses `scriptOutputsAt` under the hood, applying one extra step to accumulate total `Value` (i.e. go from `[(DatumHash, Value)]` to just `Value` summing values from list). So it will give you total `Value` that *will* be paid to a script (and locked by that script). So `valueLockedBy (scriptContextInfoTx ctx) ownHash` is *not* the total `Value` of UTxOs that currently locked by the current script, but total `Value` of UTxOs which *will* be produced by this transaction and *will* be locked at the current script when transaction succeeds.
4. So, `(valueLockedBy (scriptContextInfoTx ctx) ownHash)` and `fold $ pubKeyOutputsAt pubKeyHash (scriptContextInfoTx ctx)` are not the same in principle, as former uses script hash, and latter - public key hash , giving value for different kinds of addresses.

> **Comments:**
> **username_0**: Yes in my example scptAddress is the PubKeyHash associated with the script. Sorry if this was misleading. But essentially, in point 4 you are saying that the types of parameters differ, but they both do return the same result correct?  

---

