Error: Need to check the asset balance of SmartContract

For AssetHolding - to get token balance of a particular asset in my smartcontract, this is what I’m trying:

Global.current_application_address() = Current Contract Address

Assert(AssetHolding.balance(Global.current_application_address(), _token).hasValue() == Int(1)),
_balance.store(AssetHolding.balance(Global.current_application_address(), _token).value()),

But it gives me this error:

(Attached screenshot)

That error message isn’t great but it usually means that when you try to compile the program, the compiler cant figure out which subroutine to assign scratch slots to.

This often happens when you try to use a MaybeValue directly as you have here with AssetHolding.balance.

Try something like:

Seq(
#...
holding := AssetHolding.balance(Global.current_application_address(), _token),
Assert(holding.hasValue()),
_balance.store(holding.value()),
#...
2 Likes