1

I want to interact with the FA12.py smart contract (https://smartpy.io/demo/index.html?template=FA1.2.py) and get the balance of a user, from another smart contract.

the FA12 function that I tried to call :

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

What I tried to do from another contract:

@sp.entry_point
def getFA12Balance(self, params):
    assertTrasnferRecord = sp.TRecord(arg = sp.TRecord(owner = params.owner), target = params.address)
    entryPointName = "getBalance"
    c = sp.contract(
        t = sp.TNat,
        address = self.data.FA12Address,
        entry_point = entryPointName
    ).open_some()

    sp.transfer(assertTrasnferRecord, sp.mutez(0), c)

The answer I get :

Error: Error in Scenario 
Literal format error: (record(record((arg(record((owner(attr(params 186)owner 187)))None))(target(attr(params 186)address 187)))None))

**** EDIT ****

after fixing the format error based on FFF answer:

def getBalance(self, params):
    assertTrasnferRecord = sp.record(arg = sp.record(owner = params.owner), target = params.address)
    entryPointName = "getBalance"
    c = sp.contract(
        t = sp.TRecord(arg = sp.TRecord(owner = sp.TAddress), target = sp.TAddress),
        address = self.data.FA12Address,
        entry_point = entryPointName
    ).open_some()

    call(assertTrasnferRecord, c)

I'm still have an error when testing the function with smartpy as follows :

c2.getBalance(owner = alice.address, address = c2.address).run(sender = admin)

Error text :

Error: Error in Scenario
Unexpected error in transaction, please use .run(valid=False, ..)
ChannelNotFound: 'default'
default (18 : sp.TNat)

2 Answers 2

2
    assertTrasnferRecord = sp.TRecord(arg = sp.TRecord(owner = params.owner), target = params.address)

You're building a type sp.TRecord and put a value inside params.owner. This is not well built which leads to a Literal format error.

Instead of using sp.TRecord, you should try sp.record to build an expression (not a type).

1
  • Thank you @FFF ! That fixed the previous error, but I'm still have another one, as described in the issue edit
    – Ahmed
    Jun 9, 2020 at 9:07
1

In addition to FFF answer the type of your entry point is not “sp.TNat” so i expect after you fixed the first error he showed you will get another typing error.

When you call “open_some” you are expected to provide full specification of the entry point argument type. Please see

https://www.smartpy.io/dev/reference.html#_contract_and_address

3
  • Thank you ! That fixed the first error, but I'm still have another one..
    – Ahmed
    Jun 8, 2020 at 16:25
  • @Ahmed it’s unclear from your question edit if your problem is solved or not. Can you clarify if you still have an error after the suggested edits you made ?
    – Ezy
    Jun 8, 2020 at 22:26
  • I'm still have an error: detrails are in the issue edit
    – Ahmed
    Jun 9, 2020 at 9:07

Your Answer

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

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