Popular tags

    How to install Cairo v0.10.0 on my device?


    3 months ago




    Hello! This is day 17 of the 17 days of the Cairo Challenge. In this challenge I want to ask you install Cairo and try to launch your first program. What have you implemented as your first Cairo language program?

    Step 1

    // 1. Make sure that you installed dev packages on your device sudo apt install -y libgmp3-dev // Linux brew install gmp // Mac OS

    Step 2

    // 2. Install Cairo using Python virtual environment python3.9 -m venv ~/cairo_venv source ~/cairo_venv/bin/activate pip3 install ecdsa fastecdsa sympy; pip3 install cairo-lang;

    Step 3

    // 3. Make sure you have python 3.9. Because Cairo was tested with python3.9. To make it work with python3.6, you will have to install contextvars: pip3 install contextvars

    Step 4

    // 4. Write your program // Create a file, named hello.cairo, with the following lines: func main() { // edit me: you can add here any output, best program wins the challenge ret; } ```solidity //5. Compile your program cairo-compile hello.cairo --output hello_compiled.json

    Last step

    //6. Run: cairo-run \ --program=hello_compiled.json --print_output \ --print_info --relocate_prints //7. Debug: //You can open the Cairo tracer by providing the --tracer flag to cairo-run. Then open it at http://localhost:8100/.

    If you have questions, create them on Newton and we will help!

    Answers to this question are a part of the ✨ 17 days of Cairo Lang with Playground & Newton. ✨

    Vote for your favorite answer - the best answer will win a $10 award. A new day – a new reward! During the next 17 days, our goal is to attract more developers to the Cairo language and to systematize the knowledge of Cairo lang. Read rules




    3 months ago

    1 answers


    Accepted answer

    Step 2: If you cannot install ecdsa or fastecdsa. Maybe you need to install python3.9-dev

    sudo apt install python3.9-venv

    Step 4:

    from starkware.cairo.common.serialize import serialize_word
    from starkware.cairo.common.alloc import alloc
    struct KeyValue {
        key: felt,
        value: felt,
    func main() {
        //Create an array with 5 KeyValue elments [(3, 5), (1, 10), (3, 1), (3, 8), (1, 20)]
        let (array: KeyValue*) = alloc();
        assert array[0] = KeyValue(key=3, value=5); 
        assert array[1] = KeyValue(key=1, value=10); 
        assert array[2] = KeyValue(key=3, value=1); 
        assert array[3] = KeyValue(key=3, value=8); 
        assert array[4] = KeyValue(key=1, value=20); 
        //print 5th element
            el = ids.array.address_ + ids.KeyValue.SIZE * 4
            print([memory[el + 0]])
            print([memory[el + 1]])
        return ();

    Last step:

    Output should be like that

    Number of steps: 25 (originally, 25)
    Used memory cells: 67
    Register values after execution:
    pc = 58
    ap = 58
    fp = 58



    3 months ago

    Your answer