4

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?

2

If you are trying to do this in your offchain code, I would suggest using Plutus.Contract.utxoAt instead.

Here is an example of it being used in the gift code.

2
  • 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. Aug 13 at 23:50
  • 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. Aug 14 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.