0

When I implement a getBalance in the FA1.2 function like this:

@sp.entryPoint
def getBalance(self, params):
    return self.data.balances[params.addr]

As test:

scenario += c1.getBalance(addr = alice).run(sender = alice)

I get the above error:

Error: Type error, (sp.TRecord(addr = sp.TAddress)) is not (sp.TUnit)
3

Contratry to my initial answer, as FFF pointed out, the problem is that an entrypoint in SmartPy cannot return a value to the calling contract, nor in the underlying Michelson language. The typical solution is based on continuation-passing style. The idea is that the calling contract also provides a call back, in the form of an contract. The parameter type of this callback should be the same as the type of the "returned" value. The called contract then computes the value to be "returned", and calls the callback with that value.

  • 1
    This is not the issue. The bug here is to use a return: entry points in Michelson or SmartPy don't return values. – FFF Jan 17 '20 at 17:45
  • 1
    Indeed, I've updated my answer to reflect this. I would have liked to add an example of implementing CPS in SmartPy but couldn't find any examples in the reference. Do you have something in the IDE for example? – arvidj Jan 20 '20 at 9:14
  • There is the very example of getBalance in the FA12 which has been updated a few days ago on SmartPy.io/dev but no really satisfying example. I must admit that I'm not a big fan of currently implemented solutions or patterns. As a side note, SmartPy is now raising an exception when the user returns a value instead of silently ignoring it. – FFF Jan 20 '20 at 19:34

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.