3

From my understanding, getBalance, getAllowance, getTotalSupply & getAdministrator entrypoint requires another contract to read the values. How will the entry point of the second contract look like for getBalance for example

    @sp.entry_point
    def getBalance(self, params):
        sp.transfer(sp.as_nat(self.data.balances[params.arg.owner].balance), sp.tez(0), sp.contract(sp.TNat, params.target).open_some())
3

I am unsure how to interpret params.target, so i modified getBalance by adding an entrypoint and address

    @sp.entry_point
    def getBalance(self, params):
      sp.transfer(sp.as_nat(self.data.balances[params.arg.owner].balance), sp.tez(0), sp.contract(sp.TNat, params.contractAddress , entry_point = "viewBalance").open_some())

Here is my view contract for callback interaction

class viewerContract(sp.Contract):
    def __init__(self, contract):
        self.contract = contract
        self.init()
        
    @sp.entry_point
    def viewBalance(self, params):
        sp.set_type(params, sp.TNat)

To test the view contract in smartpy scenarios

c1 = FA12(admin.address)
c2 = viewerContract(c1)
scenario += c1
scenario.h2("Testing viewer contract")
scenario += c2
scenario += c1.getBalance(arg = sp.record(owner = bob.address), contractAddress = c2.address)
| improve this answer | |

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.