TransWikia.com

Calling view of Fa1.2 contract

Tezos Asked on August 20, 2021

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())

One Answer

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)

Answered by Vinnyson on August 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP