<p>If you are trying to do this in your offchain code, I would suggest using <a href="https://alpha.marlowe.iohkdev.io/doc/haddock/plutus-contract/html/Plutus-Contract.html#v:utxoAt" rel="nofollow noreferrer"><code>Plutus.Contract.utxoAt</code></a> instead.</p>
<p><a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/main/code/week02/src/Week02/Gift.hs#L58" rel="nofollow noreferrer">Here</a> is an example of it being used in the gift code.</p>

CC BY-SA 4.0
2021-08-13T23:50:22.403Z
I did see that example, but is there a reason why that's a better approach? It seems like `fundsAt` is a clearer and more direct way to get the data I want and I'm just struggling with the `Lens'` type.
Frank DelPidio
CC BY-SA 4.0
2021-08-14T00:07:45.893Z
They both give you a `UtxoMap`. Notice that the return type of the `grab` function is the `Contract` monad, just like `utxoAt`. It's what's meant to be used in the off-chain transaction-building code. I doubt there is a conversion between `Lens'` and `Contract`.
Mitchell Turner
CC BY-SA 4.0
2021-08-13T21:31:52.917Z
2021-08-13T21:31:52.917Z
Mitchell Turner
<p>I am currently working on Lecture 8 in the Plutus Pioneer program.</p>
<p>I want to view funds available at a script address.</p>
<p>There appears to be a function that makes this easy in <a href="https://github.com/input-output-hk/plutus/blob/master/plutus-ledger/src/Ledger/AddressMap.hs#L96-L98" rel="nofollow noreferrer">Ledger.AddressMap</a></p>
<pre><code>-- | Get the funds available at a particular address.
fundsAt :: Address -&gt; Lens' AddressMap UtxoMap
fundsAt addr = at addr . non mempty
</code></pre>
<p>However, I have not been able to get this to work.</p>
<p>When I try this</p>
<pre><code>fundsAt scriptAddress
</code></pre>
<p>I get the following error</p>
<pre><code>Ambiguous type variable ‘f0’ arising from a use of ‘fundsAt’
  prevents the constraint ‘(Prelude.Functor f0)’ from being solved.
</code></pre>
<p>My attempts at trying to make the type unambiguous have not worked, and I am struggling to understand <code>Lens'</code>.</p>
<p>Does anyone know how to get the <code>fundsAt</code> function to work?</p>

<plutus><haskell>
How to get the funds available at a script using Plutus?
# How to get the funds available at a script using Plutus?

(Asked by: username_0 on 2021-08-13)

I am currently working on Lecture 8 in the Plutus Pioneer program.
I want to view funds available at a script address.
There appears to be a function that makes this easy in Ledger.AddressMap
-- | Get the funds available at a particular address.
fundsAt :: Address -> Lens' AddressMap UtxoMap
fundsAt addr = at addr . non mempty

However, I have not been able to get this to work.
When I try this
fundsAt scriptAddress

I get the following error
Ambiguous type variable ‘f0’ arising from a use of ‘fundsAt’
  prevents the constraint ‘(Prelude.Functor f0)’ from being solved.

My attempts at trying to make the type unambiguous have not worked, and I am struggling to understand Lens'.
Does anyone know how to get the fundsAt function to work?

**Tags:** plutus, haskell

---

## 1 answers

### Answer by username_1 on 2021-08-13. Score: 2 | Accepted answer

If you are trying to do this in your offchain code, I would suggest using [`Plutus.Contract.utxoAt`](https://alpha.marlowe.iohkdev.io/doc/haddock/plutus-contract/html/Plutus-Contract.html#v:utxoAt) instead.

[Here](https://github.com/input-output-hk/plutus-pioneer-program/blob/main/code/week02/src/Week02/Gift.hs#L58) is an example of it being used in the gift code.

> **Comments:**
> **username_0**: I did see that example, but is there a reason why that's a better approach? It seems like `fundsAt` is a clearer and more direct way to get the data I want and I'm just struggling with the `Lens'` type.  
> **username_1**: They both give you a `UtxoMap`. Notice that the return type of the `grab` function is the `Contract` monad, just like `utxoAt`. It's what's meant to be used in the off-chain transaction-building code. I doubt there is a conversion between `Lens'` and `Contract`.  

---

