When I return a list from an on-chain view am receiving a type error but am unsure where to set the type in order to fix it.

Returning a string or integer from the view works fine. Is there a set limit on the types that can be returned from on-chain views, or is there somewhere I should be explicitly declaring the return types?

I have included a link to a minimal contract on smartpy ide with issue reproduction, and include the code below for reference.

Example Contract:

class OnChainViewTestContract(sp.Contract):
    def __init__(self, **kargs):

    def run_str_example(self):

    def run_int_example(self):

    def run_list_example(self):

The int and str examples work in the tests below, but the list example fails.

@sp.add_test(name = "OnChainViewReturnTypes")
def test():
    scenario = sp.test_scenario()
    scenario.h1("On-chain view return types test")
    contract = OnChainViewTestContract(
        strExample = 'some_string',
        intExample = 2,
        listExample = ['a', 'b', 'c']        
    scenario += contract
    s = contract.run_str_example()
    i = contract.run_int_example()
    l = contract.run_list_example()

    scenario.verify(s == 'some_string')
    scenario.verify(i == 2)
    scenario.verify(l == ['a', 'b', 'c'])

The resulting error:

Error: Type error (sp.contract_view(0, "run_list_example", sp.unit).open_some(message = 'View run_list_example is invalid!') : sp.TList(sp.TString)) doesn't have a comparable type
(__main__, line 36)

SmartPy IDE Unit Test Link

1 Answer 1


You cannot compare lists in Tezos.

However, you can use scenario.verify_equal.

  • thank you, is there a list of all incomparable types in tezos somewhere?
    – 0x10
    Commented May 1, 2022 at 3:27
  • 1
    You have a list of characteristics including comparability for each type in this documentation tezos.gitlab.io/michelson-reference.
    – FFF
    Commented May 1, 2022 at 15:01

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.