Error: Type sp.TInt / sp.TNat mismatch
sp.is_nat expects a sp.TInt
Got: sp.TNat
line 119

Line: 119

self.data.shop_items[item_to_purchase.key].amount -= sp.as_nat(item_to_purchase.value)

I'm not sure where the sp.TInt is coming from... All the numbers are supposed to be sp.TNat

1 Answer 1


Doing math on nats casts them to an int. The value needs to be casted back to a nat after the subtraction:

self.data.shop_items[item_to_purchase.key].amount = sp.as_nat(self.data.shop_items[item_to_purchase.key].amount - item_to_purchase.value)
  • 1
    Not all math. Only when they involve a difference (of the unitary minus operator). Otherwise, your answer is good!
    – FFF
    Commented Jun 24, 2021 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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