<blockquote>
<p>is there a way for the smart contract to read all UTxOs on its own address</p>
</blockquote>
<p>No. The transaction submitter can pick and choose which UTxOs to include in the transaction (which UTxOs will be visible to the script).</p>
<p>However, you can write the script in a way that requires a certain set of UTxOs be include in the redeeming transactions.</p>
<p>Hope that helps.</p>

CC BY-SA 4.0
2021-09-16T21:32:17.257Z
2021-09-16T21:32:17.257Z
Mitchell Turner
<p>In the off-chain code, you probably want to use the Contract monad. In the on-chain code (validator), you can use <code>TxInfo</code>. So, for each <code>TxOut</code> given by <code>txInfoOutputs</code> you can use <a href="https://playground.plutus.iohkdev.io/tutorial/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Tx.html#v:TxOut" rel="nofollow noreferrer"><code>txOutValue</code></a> to get the address, and on that value, you can run <a href="https://playground.plutus.iohkdev.io/tutorial/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Value.html#v:valueOf" rel="nofollow noreferrer"><code>valueOf</code></a> to get the number of Ada or whichever token you are trying to compare the value of. From that, just pop it into the validator and have it throw an error if it is beneath your specified value.</p>
<p><a href="https://plutus-pioneer-program.readthedocs.io/en/latest/week5.html?highlight=own#id8" rel="nofollow noreferrer">Ref</a></p>

CC BY-SA 4.0
2021-09-16T20:45:30.670Z
Thanks. Your answer made me realize that I have to rephrase my question. Please see my edit.
Xiaofei
CC BY-SA 4.0
2021-09-16T14:50:13.857Z
2021-09-16T14:50:13.857Z
Noah Jones
<p>While building your transaction on the off-chain code, you can instruct it to consume all the utxos at a certain address (it can be your SC address).</p>
<p>Then in your smart contract on-chain, you can access these utxos from TxInfo of your Context.</p>
<p>From there you can access the value inside each of those utxos, do your math and act accordingly.</p>

CC BY-SA 4.0
2021-09-17T05:27:34.590Z
2021-09-17T05:27:34.590Z
Jelil Akjaly
<p>As the title says, is there a way for the smart contract to read all UTxOs on its own address and also verify that <strong>all</strong> UTxOs were used to determine token count on the address.</p>
<p>For example users send funds to the SC address, each in their own utxo as they don't interact with the script. When the total funds (all UTxOs combined) hit a specific amount, you are allowed to withdraw them.</p>

<plutus><smart-contract>
Can a smartcontract access the state of its own address?
# Can a smartcontract access the state of its own address?

(Asked by: username_0 on 2021-09-16)

As the title says, is there a way for the smart contract to read all UTxOs on its own address and also verify that **all** UTxOs were used to determine token count on the address.

For example users send funds to the SC address, each in their own utxo as they don't interact with the script. When the total funds (all UTxOs combined) hit a specific amount, you are allowed to withdraw them.

**Tags:** plutus, smart-contract

---

## 3 answers

### Answer by username_1 on 2021-09-16. Score: 1

> is there a way for the smart contract to read all UTxOs on its own address

No. The transaction submitter can pick and choose which UTxOs to include in the transaction (which UTxOs will be visible to the script).

However, you can write the script in a way that requires a certain set of UTxOs be include in the redeeming transactions.

Hope that helps.


---

### Answer by username_2 on 2021-09-16. Score: 0

In the off-chain code, you probably want to use the Contract monad. In the on-chain code (validator), you can use `TxInfo`. So, for each `TxOut` given by `txInfoOutputs` you can use [`txOutValue`](https://playground.plutus.iohkdev.io/tutorial/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Tx.html#v:TxOut) to get the address, and on that value, you can run [`valueOf`](https://playground.plutus.iohkdev.io/tutorial/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Value.html#v:valueOf) to get the number of Ada or whichever token you are trying to compare the value of. From that, just pop it into the validator and have it throw an error if it is beneath your specified value.

[Ref](https://plutus-pioneer-program.readthedocs.io/en/latest/week5.html?highlight=own#id8)

> **Comments:**
> **username_0**: Thanks. Your answer made me realize that I have to rephrase my question. Please see my edit.  

---

### Answer by username_3 on 2021-09-17. Score: 0

While building your transaction on the off-chain code, you can instruct it to consume all the utxos at a certain address (it can be your SC address).

Then in your smart contract on-chain, you can access these utxos from TxInfo of your Context.

From there you can access the value inside each of those utxos, do your math and act accordingly.


---

