I have two codes, Utils = sp.io.import_script_from_url("https://raw.githubusercontent.com/RomarQ/tezos-sc-utils/main/smartpy/utils.py")



both of the response should give 2 as integer

sp.if (sp.len(sp.bytes("0x0001")) == Utils.Int.of_string("2")):

but the above if statement is giving data type mismatch issue. How to fix this ?

2 Answers 2


Michelson is strongly typed and comparisons are not overloaded. In your code you need to make sure both values have the same type when comparing them.

This is probably what you want:

import smartpy as sp

Utils = sp.io.import_script_from_url("https://raw.githubusercontent.com/RomarQ/tezos-sc-utils/main/smartpy/utils.py")

class Test(sp.Contract):
    def test(self):
        len_nat = sp.len(sp.bytes("0x0001"))
        two_int = Utils.Int.of_string("2")

        sp.verify(sp.to_int(len_nat) == two_int)

@sp.add_test(name = "Test")
def test():
    c1 = Test()
    scenario = sp.test_scenario()
    scenario += c1

sp.len with give you the output in Nat data type and Utils.Int.of_string("2") is a String data type. That might me the issue here.

  • Utils.Int.of_string("2") it is of int data type and converting it into nat also didn't work
    – Kin
    Commented Apr 12, 2023 at 7:38

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.