NEWTON

NEWTON


Popular tags

    Cairo: How to return true from a function?

    Asked

    5 months ago

    11

    views


    0

    Is there an equivalent of return (true) in cairo on Starknet?

    This question was originally posted on Triality

      cairo-langstarknet

    2 answers

    0

    Just to add to the existing valid answer:

    StarkWare also provides a library for this: starkware.cairo.common.bool . You can import it with from starkware.cairo.common.bool import TRUE, FALSE and then use TRUE and FALSEin your code. In reality, the library simple maps true to 1 and false to 0 (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/bool.cairo)

    This answer was originally posted on Triality

    answered

    6 months ago

    0

    There is no boolean type in Cairo but you can return a felt with value 1. For example:

    func test() -> (success: felt):

    return (1)

    end

    This answer was originally posted on Triality

    answered

    6 months ago

    Your answer

    NEWTON

    NEWTON